#!/bin/sh
#
# monit		Monitoring daemon
#
# chkconfig:	345 99 01
# description:	Monitoring daemon
#

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

# Get service config
[ -f /etc/sysconfig/monit ] && . /etc/sysconfig/monit

start() {
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/monit ]; then
		msg_starting monit
		daemon monit -c /etc/monitrc -l syslog -d 60
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/monit
	else
		msg_already_running monit
	fi
}

stop() {
	# Stop daemons.
	if [ -f /var/lock/subsys/monit ]; then
		msg_stopping monit
		daemon monit -c /etc/monitrc quit
		rm -f /var/lock/subsys/monit > /dev/null 2>&1
	else
		msg_not_running monit
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
	stop
	start
	;;
  reload|force-reload)
	if [ -f /var/lock/subsys/monit ]; then
		msg_reloading monit
		daemon monit -c /etc/monitrc reload
		RETVAL=$?
	else
		msg_not_running monit
		exit 7
	fi
	;;
  status)
	status monit
	monit -c /etc/monitrc status
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
