#
# Adding service to autostart
# $1 = service name
#
startService() {
    app_name=$1
    if hash update-rc.d >/dev/null 2>&1; then
		echo "Adding $app_name to autostart using update-rc.d"
		update-rc.d $app_name defaults
		service $app_name start
    elif hash chkconfig >/dev/null 2>&1; then
		echo "Adding $app_name to autostart using chkconfig"
		chkconfig --add thehive
		chkconfig $app_name on
		service $app_name start
    else
		echo "WARNING: Could not add $app_name to autostart: neither update-rc nor chkconfig found!"
    fi
}

#
# Removing service from autostart
# $1 = service name
#
stopService() {
    app_name=$1
    if hash update-rc.d >/dev/null 2>&1; then
	echo "Removing $app_name from autostart using update-rc.d"
	update-rc.d -f $app_name remove
	service $app_name stop
    elif hash chkconfig >/dev/null 2>&1; then
	echo "Removing $app_name from autostart using chkconfig"
	chkconfig $app_name off
	chkconfig --del $app_name
	service $app_name stop
    else
	echo "WARNING: Could not remove $app_name from autostart: neither update-rc nor chkconfig found!"
    fi

}

#
# Restarting the service after package upgrade
# $1 = service name
#
restartService() {
	app_name=$1
	service $app_name restart
}


# Scriptlet syntax: http://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Syntax
# $1 == 1 is upgrade and $1 == 0 is uninstall
if [ $1 -eq 0 ] ;
then
    stopService thehive || echo "Could not stop thehive"
fi
