#!/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

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

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

test -x $DAEMON || exit 1

DAEMON_OPTS=""

RETVAL=0


start() {
        if [ -a $PIDFILE ];
        then
                echo "essm appears to be running, or has crashed, or was not stopped properly."
                echo "check and remove $PIDFILE to start again."
                RETVAL=1
                return $RETVAL;
        fi

        echo -n $"Starting $NAME: "
        $DAEMON $DAEMON_OPTS >/dev/null 2>&1 &
        RETVAL=$?
        echo
        return $RETVAL
}
stop() {
        if [ -a $PIDFILE ]
        then
                echo -n $"Stopping $NAME: "
                kill `cat ${PIDFILE}`
                RETVAL=$?
                echo
                [ $RETVAL = 0 ] && rm -f ${PIDFILE}
        else
                echo "essm appears not to be running."
        fi
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        sleep 5
        start
        ;;
  status)
        status -p ${PIDFILE} $DAEMON
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $NAME {start|stop|restarts|status}"
        exit 1
esac

exit $RETVAL
