#!/bin/sh

##
# Start monit
##

##
# *** caveat: this type of StartupItem is obsolete as of Mac OS X v10.3 ***
# name this file "monit", place in folder /Library/StartupItems/monit
# add "MONIT=-YES-" to /etc/hostconfig
##

. /etc/rc.common

StartService ()
{
# assumes "daemon"; polling period and other options defined in /etc/monitrc
if [ "${MONIT:=-NO-}" = "-YES-" ]; then
	if [ -x /usr/local/bin/monit ]; then
		ConsoleMessage "Starting monit System Monitor"
	  su - root -c /usr/local/bin/monit
	fi
fi
}

StopService ()
{
  ConsoleMessage "Stopping monit System Monitor"
	su - root -c "/usr/local/bin/monit quit"
	sleep 1
	if [ -f /var/run/monit.pid ]; then
		kill -KILL $(cat /var/run/monit.pid) >/dev/null 2>&1
		rm -f /var/run/monit.pid
	fi
}

RestartService ()
{
  ConsoleMessage "Reloading monit System Monitor"
	su - root -c "/usr/local/bin/monit reload"
}

RunService "${1:-None}"

