#!/bin/sh

DESC="monit"
DAEMON=/usr/bin/monit
PID_FILE=/var/run/monit.pid

TESTFILE=/tmp/testsoftwareEnabled
MONITNORMAL=/etc/monitrcNormal
MONITTEST=/etc/monitrcTest

# Make sure the progam exists
[ -f $DAEMON ] || exit 0

start() {
    if [ -f $TESTFILE ];
    then
        echo "Config monit test"
        cp $MONITTEST /etc/monitrc
    else
        echo "Config monit normal"
        cp $MONITNORMAL /etc/monitrc
    fi


    echo -n "Starting $DESC: "
    start-stop-daemon -S -q -b --exec $DAEMON
    echo "done"
}
stop() {
    echo -n "Stopping $DESC: "
    start-stop-daemon -K -q -n $DAEMON
    echo "done"
}
restart() {
    stop
    sleep 1
    start
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart|reload)
        restart
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac

exit $?
