#!/bin/bash
#
# psa-health-monitor-notificationd -    Startup script for the Parallels Panel Health Monitor Notification Daemon
# chkconfig: - 86 15
# description: start Parallels Panel Health Monitor Notification Daemont to dispatch notifications.
# pidfile: /var/run/psa-health-monitor-notificationd.pid

# Source function library.
. /etc/init.d/functions

RETVAL=0
BINARY="/usr/bin/sw-engine"
ARGS="-c  /usr/local/psa/admin/conf/php.ini /usr/lib/plesk-9.0/psa-health-monitor-notification.php"
SERVICENAME="PP HM notification daemon"
SERVICE="psa-health-monitor-notificationd"
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

start () {
	echo -n $"Starting $SERVICENAME: "
	daemon --check $SERVICE $BINARY $ARGS
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SERVICE
}
stop () {
	echo -n $"Stopping $SERVICENAME: "
	killproc $SERVICE
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$SERVICE
}

status() {
	local pid
	if [ -f "$PIDFILE" ]; then
		read pid_r < $PIDFILE
		for pid in `pidof -o $$ -o $PPID -o %PPID -x $BINARY`; do
			if [ "$pid" -eq "$pid_r" ]; then
				echo "${SERVICE} (pid $pid) is running..."
				return 0
			fi
		done
		echo $"${SERVICE} dead but pid file exists"
		return 1
	fi

	if [ -f /var/lock/subsys/$SERVICE ]; then
			echo $"${SERVICE} dead but subsys locked"
			return 2
	fi

	echo $"${SERVICE} is stopped"
	return 3
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status
	;;
  restart|reload)
	stop
	start
	;;
  condrestart)
	[ -f /var/lock/subsys/$SERVICE ] && stop && start || :
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
	exit 1
esac

exit $?

# vim:syntax=sh
