#!/bin/sh

#
# Sample init script for M/Monit to be placed in /etc/init.d/ and linked to run levels
#


DESC="mmonit"
NAME=mmonit
DAEMON=/usr/local/mmonit/bin/$NAME
SCRIPTNAME=/etc/init.d/$NAME
PIDFILE=/var/run/mmonit.pid

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

d_start() {
        $DAEMON -p /var/run/ || echo -en "\n already running"
}

d_stop() {
        kill -QUIT `cat $PIDFILE` || echo -en "\n not running"
}

d_reload() {
        kill -HUP `cat $PIDFILE` || echo -en "\n can't reload"
}

case "$1" in
        start)
                echo -n "Starting $DESC: $NAME"
                d_start
                echo "."
                ;;
        stop)
                echo -n "Stopping $DESC: $NAME"
                d_stop
                echo "."
                ;;
        reload)
                echo -n "Reloading $DESC configuration..."
                d_reload
                echo "."
                ;;
        restart)
                echo -n "Restarting $DESC: $NAME"
                d_stop
                sleep 5
                d_start
                echo "."
                ;;
        *)
                echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
                exit 3
                ;;
esac

exit 0

