#! /bin/sh
#
# monit         Monitors processes and restarts them if they exit
#
# Author:	"Jan-Henrik Haukeland" <hauk@tildeslash.com>
#
# chkconfig: 345 98 02
# description: monit is a simple daemon process to restart processes if \
#		they die. It can also check tcp and udp ports to make sure \
#		that they are responding.
# processname: monit
# pidfile: /var/run/monit.pid
# config: /etc/monit.conf


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

[ -f /usr/bin/monit ] || exit 0

RETVAL=0

# See how we were called.
case "$1" in
  start)
	echo -n "Starting monit: "
	daemon monit -c /etc/monit.conf -l syslog -d 60
	RETVAL=$?

	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/monit
	;;
  stop)
	echo -n "Stopping monit: "
	killproc monit
	RETVAL=$?

	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/monit
	;;
  status)
	status monit
	RETVAL=$?
	;;
  restart)
  	$0 stop
	$0 start
	RETVAL=$?
	;;
  reload)
	killall -HUP monit
	RETVAL=$?
	;;
  *)
	echo "Usage: inet {start|stop|status|restart|reload}"
	exit 1
esac

exit $RETVAL
