#! /bin/sh
#
# savdid        /etc/init.d/ initscript for savdid
#
#
# How this thing works:
#   ${START} must be only what is needed for start-stop-daemon, DO NOT
#   ADD ANY PARAMETERS HERE!  we might use it for --test, for example.
#   ${STOP} works just like ${START}, --signal is used with it.
#
#   ${PARAMS} are the parameters to give the daemon when really starting
#   it.
### BEGIN INIT INFO
# Provides:          savdid
# Required-Start:    $syslog $network $local_fs $remote_fs
# Required-Stop:     $syslog $network $local_fs $remote_fs
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts savdid AntiVirus
# Description:       Launches the savdid AntiVirus daemon
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/savdid
NAME=savdid
DAEMONNAME=savdid
DESC=savdid
PIDFILE=/var/run/savdid/${NAME}.pid

. /lib/lsb/init-functions

test -f ${DAEMON} || exit 0

set -e

START="--start --quiet --pidfile $PIDFILE --exec ${DAEMON}"
STOP="--stop --quiet --pidfile $PIDFILE"
PARAMS="-d"

case "$1" in
  start)
        echo -n "Starting $DESC: "
        mkdir -p /var/run/savdid
        if start-stop-daemon ${START} -- ${PARAMS} >/dev/null ; then
                echo "savdid."
        else
                if start-stop-daemon --test ${START} >/dev/null 2>&1; then
                        echo "(failed)."
                        exit 1
                else
                        echo "(already running)."
                        exit 0
                fi
        fi
        ;;
  stop)
        echo -n "Stopping $DESC: "
        if start-stop-daemon ${STOP} --retry 10 >/dev/null ; then
                echo "savdid."
        else
                if start-stop-daemon --test ${START} >/dev/null 2>&1; then
                        echo "(not running)."
                        exit 0
                else
                        echo "(failed)."
                        exit 1
                fi
        fi
        ;;
  restart|force-reload)
        $0 stop
        exec $0 start
        ;;
  status)
        status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
        ;;
  *)
        N=/etc/init.d/savdid
        echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
        exit 1
        ;;
esac

exit 0

