#!/bin/bash
#
# essm          Start essm daemon
#
# chkconfig: 2345 55 25
# description: Every Single Second Monitoring
#
# processname: essm
# config: /etc/essm.conf
# pidfile: /var/run/essm.pid

### BEGIN INIT INFO
# Provides: essm
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Should-Start: 
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start ad stop pessm  daemon
# Description:       Every Single Second Monitoring
### END INIT INFO

NAME=essm
PIDFILE="/var/run/$NAME.pid"
DAEMON="/usr/bin/essm"
DAEMON_ARGS=""

case "$1" in
    start)
        echo "Starting "$NAME" "
        start-stop-daemon --start --verbose --background --pidfile $PIDFILE --make-pidfile --startas $DAEMON -- $DAEMON_ARGS
        ;;
    stop)
        echo "Stopping "$NAME" "
        start-stop-daemon --stop --verbose --pidfile $PIDFILE
        rm -f $PIDFILE
        ;;
    restart)
        echo "Restarting "$NAME" "
        start-stop-daemon --stop --verbose --pidfile $PIDFILE
        rm -f $PIDFILE
        sleep 5
        start-stop-daemon --start --verbose --background --pidfile $PIDFILE --make-pidfile --startas $DAEMON -- $DAEMON_ARGS
        ;;
    status)
		start-stop-daemon --status --pidfile $PIDFILE -x $DAEMON -n $NAME && exit 0 || exit $?
    	;;
    *)
        echo "Usage: ""$(basename "$0")"" {start|stop|restart|status}"
        echo "    Starts the essm as a daemon."
        exit 1
        ;;
esac

exit 0