#! /bin/sh
### BEGIN INIT INFO
# Provides:          psa-health-monitor-notificationd
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Default-Start:     2 3
# Default-Stop:      0 1 5 6
# Short-Description: Parallels Panel Health Monitor Notification Daemon
# Description:       start Parallels Panel Health Monitor Notification Daemont to dispatch notifications.
### END INIT INFO

binary="/usr/bin/sw-engine"
arguments="-c /usr/local/psa/admin/conf/php.ini /usr/lib/plesk-9.0/psa-health-monitor-notification.php"
servicename="PP HM notification daemon"
pidfile="/var/run/psa-health-monitor-notificationd.pid"

test -x "$binary" || exit 0

test -r "/usr/lib/plesk-9.0/psa-health-monitor-notification.php" || exit 6

. /etc/rc.status
# Reset status of this service
rc_reset

case "$1" in
    start)
	echo -n "Starting $servicename "
	/sbin/startproc -p "$pidfile" "$binary" $arguments
	rc_status -v
	;;
    stop)
	echo -n "Shutting down $servicename "
	/sbin/killproc -p "$pidfile" -TERM "$binary"
	rc_status -v
	;;
    try-restart|condrestart)
	## Do a restart only if the service was active before.
	## Note: try-restart is now part of LSB (as of 1.9).
	## RH has a similar command named condrestart.
	if test "$1" = "condrestart"; then
		echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
	fi
	$0 status
	if test $? = 0; then
		$0 restart
	else
		rc_reset	# Not running is not a failure.
	fi
	rc_status
	;;
    restart)
	$0 stop
	$0 start
	rc_status
	;;
    force-reload)
	echo -n "Reload service $servicename "
	$0 try-restart
	rc_status
	;;
    reload)
	rc_failed 3
	rc_status -v
	;;
    status)
	echo -n "Checking for service $servicename "
	/sbin/checkproc -p "$pidfile" $binary
	rc_status -v
	;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
	exit 1
	;;
esac
rc_exit
