#! /bin/sh
### BEGIN INIT INFO
# Provides:          revexscanD
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: revexscanD
# Description:       Start Stop rebound
### END INIT INFO


BASE=/usr/local/reveantivirus/bin
NAME=revexscanD
BNAME=rebound
DAEMON=${BASE}/rebound
SCRIPTNAME=/etc/init.d/$NAME
pidFPath=/usr/local/reveantivirus/conf/.rebound.lock
start()
{
	isProc=`pidof $BNAME`
	isProcVal=`expr $isProc + 1`
	if [ $isProcVal -gt 1 ];
	then
		echo "Service is already running"
	else
		sleep 1
		start-stop-daemon --exec $DAEMON --start
		sleep 1
		echo "$BNAME started"
	fi
}
stop()
{
	if [ -f "$pidFPath" ];
	then
	rm $pidFPath
	start-stop-daemon --exec $DAEMON --stop > /dev/null
	sleep 2
	fi

	isProc=`pidof $BNAME`
	isProcVal=`expr $isProc + 1`
	if [ $isProcVal -gt 1 ];
	then
		kill -9 $isProc > /dev/null
		sleep 3
	fi

}
status()
{
	isProc=`pidof $BNAME`
	isProcVal=`expr $isProc + 1`
	if [ $isProcVal -gt 1 ];
	then
		echo "$NAME service is running"
	else
		echo "$NAME service is stopped"
	fi
}
restart()
{
	stop
	sleep 5
	start
	echo "$NAME Restarted"
}
# Check root user.
if [ $(id -u) -ne 0 ]
then
        if [ "$1" != "start" -a "$1" != "stop" -a "$1" != "status" ];
        then
                echo "Usage: {start|stop|restart|status}" >&2
                exit 0
        fi

        if [ "$1" != "status" ]
        then
                echo "Not a root user. Please login as root user.";
                exit 0
        fi
fi
if [ ! -f $DAEMON ]; then
	exit 0
fi

check_process()
{
    # Check if the process is already running. Ignore grep line.
    result=`ps aux | grep $BNAME | grep -v grep | wc -l`
}
# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

PATH="/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin"


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