#!/bin/sh
#
# spamassassin This script starts and stops the spamd daemon
#
# chkconfig: 2345 80 30
#
# description: spamd is a daemon process which uses SpamAssassin to check \
#              email messages for SPAM.  It is normally called by spamc \
#              from a MDA.
# processname: spamd
# pidfile:     /var/run/spamassassin.pid

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

# Source networking configuration.
. /etc/sysconfig/network

SPAMD_OPTS="-d -c"
# Source configureation.
if [ -f /etc/sysconfig/spamd ] ; then
	. /etc/sysconfig/spamd
fi

# Check that networking is up.
if is_no "${NETWORKING}"; then
	msg_network_down "SpamAssassin"
	exit 1
fi

start() {
	# Start daemon.
	if [ -f /var/lock/subsys/spamd ]; then
		msg_already_running "SpamAssassin"
		return
	fi

	msg_starting "SpamAssassin"
	daemon /usr/bin/spamd $SPAMD_OPTS
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/spamd
}

stop() {
	# Stop daemons.
	if [ ! -f /var/lock/subsys/spamd ]; then
		msg_not_running "SpamAssassin"
		return
	fi

	msg_stopping "SpamAssassin"
	killproc spamd
	RETVAL=$?
	rm -f /var/lock/subsys/spamd
}

condrestart() {
	if [ ! -f /var/lock/subsys/spamd ]; then
		msg_not_running "SpamAssassin"
		RETVAL=$1
		return
	fi

	stop
	start
}

# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  force-reload)
	condrestart 7
	;;
  status)
	status spamd
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
	exit 1
esac

exit $RETVAL
