#!/bin/sh
#
#  Dr.Web (R) init script
#  $Revision: 1.10.4.1 $
#

# PROVIDE: drwebd
# REQUIRE: LOGIN
# BEFORE: drweb-sendmail drweb-icapd
# KEYWORD: drwebd
BIN="drwebd"
PROGRAM="/usr/local/drweb/$BIN"
PIDFILE="/var/drweb/run/drwebd.pid"

check_pidfile()
{
    pid=`head -1 $PIDFILE` || { echo "cannot read PID file"; exit 1; }
    [ "$pid" != "" ] && [ "$pid" -lt 100000 ] || { echo "invalid PID file for $PIDFILE"; exit 1; }
}



case "$1" in
    stop)
	echo -n "Shutting down Dr. Web daemon..."
    if [ -f $PIDFILE ] ; then
	check_pidfile;
    	kill `head -1 $PIDFILE`    
    fi
    ;;
    reload)
	echo -n "Reloading Dr. Web daemon..."
    if [ -f $PIDFILE ] ; then
	check_pidfile;
    	kill -HUP `head -1 $PIDFILE`    
    fi
    ;;
    restart)
	echo -n "Restarting Dr. Web daemon..."
    if [ -f $PIDFILE ] ; then
	check_pidfile;
    	kill `head -1 $PIDFILE`    
    fi
	sleep 3
	$PROGRAM
    ;;
    faststart|start)
	echo -n "Starting Dr. Web daemon..."
	$PROGRAM
    ;;
    *)
    echo $0: 'faststart|start|stop|restart|reload'
    ;;
esac
 