#! /bin/sh
#
#   Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#   Modified for Debian by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#   Modified for p3scan by Mats Rynge <mats@rynge.net>
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/p3scan
NAME=p3scan
DESC="transparent pop3 virus- and spam-scanner"
PIDFILE=/var/run/p3scan/p3scan.pid

test -x $DAEMON || exit 0

set -e

# Read config
DEFAULTFILE=/etc/default/p3scan
DAEMON_OPTS=
if [ -f $DEFAULTFILE ]; then
    . $DEFAULTFILE
fi


case "$1" in
  start)
      echo -n "Starting $DESC: "
      start-stop-daemon --start --quiet \
          --pidfile /var/run/p3scan/$NAME.pid \
          --exec $DAEMON -- $DAEMON_OPTS
      echo "$NAME."
      ;;

  stop)
      echo -n "Stopping $DESC: "
      start-stop-daemon --stop --quiet \
          --pidfile /var/run/p3scan/$NAME.pid \
          --exec $DAEMON || /bin/true
      echo "$NAME."
      rm -f $PIDFILE
      ;;

  restart|force-reload)
      echo -n "Restarting $DESC: "
      start-stop-daemon --stop --quiet \
          --pidfile /var/run/p3scan/$NAME.pid \
          --exec $DAEMON || /bin/true
      sleep 1
      rm -f $PIDFILE
      start-stop-daemon --start --quiet \
          --pidfile /var/run/p3scan/$NAME.pid \
          --exec $DAEMON -- $DAEMON_OPTS
      echo "$NAME."
      ;;

  *)
      N=/etc/init.d/$NAME
      echo "Usage: $N {start|stop|restart|force-reload}" >&2
      exit 1
      ;;
 
esac

exit 0

