#!/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.

# Source function library.
if [ -f /etc/init.d/functions ]; then
	. /etc/init.d/functions
fi

# Source networking configuration.
if [ -f /etc/sysconfig/network ]; then
	. /etc/sysconfig/network

	# Check that networking is up.
	[ ${NETWORKING} = "no" ] && exit 0
fi

# this way is for SuSE Linux
test -s /etc/rc.status && . /etc/rc.status && rc_reset

# Source spamd configuration.
if [ -f /etc/sysconfig/spamassassin ] ; then
        . /etc/sysconfig/spamassassin
else
        SPAMDOPTIONS="-d -c -a -m5 -H"
fi

[ -f /usr/bin/spamd -o -f /usr/local/bin/spamd ] || exit 0
PATH=$PATH:/usr/bin:/usr/local/bin

if ! type status >/dev/null 2>/dev/null; then
	status() {
		/sbin/pidof >/dev/null spamd
	}
fi

if ! type daemon >/dev/null 2>/dev/null; then
	daemon() {

		# make sure it doesn't core dump anywhere; while this could mask
		# problems with the daemon, it also closes some security problems
		ulimit -S -c 0 >/dev/null 2>&1

		$*
	}
fi

# See how we were called.
case "$1" in
  start)
	# Start daemon.
	echo -n "Starting spamd: "
	daemon spamd $SPAMDOPTIONS
	RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/spamassassin
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down spamd: "
        killproc spamd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/spamassassin
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  condrestart)
       [ -e /var/lock/subsys/spamassassin ] && $0 restart
       ;;
  status)
	status spamd
	;;
  *)
	echo "Usage: $0 {start|stop|restart|status|condrestart}"
	exit 1
esac

exit 0
