#! /bin/sh
#
#  start/stop amavisd daemon ver 1.0
#  Orginaly done for Debian GNU/Linux (/etc/init.d script)
#  by Tomasz Antosik <tomek@linux.com.pl>
#
#  You can redistribute it in any way you want to.
#

CAT=/bin/cat
SU=/bin/su
KILL=/bin/kill
USER=amavis
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/amavisd
NAME=amavisd
DESC="AMAVIS(d) (Mail Virus Scanner Interface)"
PIDDIR=/var/amavis
PIDFILE=amavisd.pid

test -x $DAEMON || exit 0

set -e

case "$1" in
  start)
	echo -n "Starting $DESC: "
	$SU $USER -c "$DAEMON >/dev/null 2>&1"
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	$KILL -9 `$CAT $PIDDIR/$PIDFILE`
	echo "$NAME."
	;;
  reload|force-reload)
	echo -n "Reloading $DESC configuration files: "
	$KILL -HUP `$CAT $PIDDIR/$PIDFILE`
	echo "$NAME."
	;;
  restart)
	echo -n "Stopping $DESC: "
	$KILL -9 `$CAT $PIDDIR/$PIDFILE`
	echo "$NAME."
	sleep 2
	echo -n "Starting $DESC: "
	$SU $USER -c "$DAEMON >/dev/null 2>&1"
	echo "$NAME."
	;;
  *)
	echo "Usage: /etc/init.d/$NAME {start|stop|restart|reload|force-reload}" >&2
	exit 1
	;;
esac

exit 0
