#! /bin/sh
#
# smtp-gated	Start/Stop the SMTP antivirus daemon.
#
# chkconfig:	2345 90 60
# description:	smtp-gated is a UNIX program that scans SMTP mail for spam and viruses.\
#		Can be installed on Linux NA(P)T router and scan mail transparently \
#		using ClamAV daemon & netfilter framework and SpamAssassin. Can also scan \
#		traffic to one fixed MTA.
# processname:	smtp-gated
# config:	/etc/smtp-gated.conf
# pidfile:	/var/run/smtp-gated/smtp-gated.pid


# Source function library.
. /etc/rc.d/init.d/functions

prog="smtp-gated"
CONFIG="/etc/smtp-gated.conf"

# Source configuration
[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

RETVAL=0
# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/$prog ]; then
		msg_starting "$prog"
		daemon $prog "$CONFIG"
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
	else
		msg_already_running "$prog"
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/$prog ]; then
		msg_stopping "$prog"
		pidfile=`$prog -t "$CONFIG" | awk '(/^pidfile/) {print $2}'`
		killproc --pidfile $pidfile $prog
		rm -f /var/lock/subsys/$prog
	else
		msg_not_running "$prog"
	fi
	;;
  restart)
	$0 stop
	$0 start
	;;
  reload)
	if [ -f /var/lock/subsys/$prog ]; then
		msg_reloading "$prog"
		$prog -t "$CONFIG" >/dev/null
		if [ "$?" = "0" ]; then
			busy
			$prog -r "$CONFIG"
			ok
			RETVAL=$?
		else
			fail
		fi
	else
		msg_not_running "$prog"
		exit 7
	fi
	;;
  status)
	$prog -s "$CONFIG"
	;;
  *)
	msg_usage "$0 {start|stop|status|reload|restart}"
	exit 3
esac

exit $RETVAL
