#!/bin/sh
#
# monit         Monitor Unix systems
#
# Author:	Clinton Work,   <work@scripty.com>
#
# chkconfig:    345 85 02
# description:  Monit is a utility for managing and monitoring processes,
#               files, directories and devices on a Unix system. 
# processname:  monit
# pidfile:      /var/run/monit.pid
# config:       /etc/monitrc

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

MONIT=/usr/local/bin/monit
MONITRC=/etc/monitrc
LOCKFILE=/var/lock/subsys/monit

[ -x $MONIT ] || exit 0
[ -f $MONITRC ] || exit 0

RETVAL=0

start() {
	echo -n "Starting monit: "
	daemon --force $MONIT -c $MONITRC
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch $LOCKFILE
}

stop() {
	echo -n "Stopping monit: "
	daemon --force $MONIT -c $MONITRC quit
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
}

reload() {
	echo -n "Reloading monit: "
	daemon --force $MONIT -c $MONITRC reload
	RETVAL=$?
	echo
}

status() {
	$MONIT -c $MONITRC status
	RETVAL=$?
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
  	stop
	start
	RETVAL=$?
	;;
  reload)
	reload
	;;
  status)
	status
	;;
  *)
	echo "Usage: $0 {start|stop|restart|reload|status}"
	exit 1
esac

exit $RETVAL
