#!/bin/sh
#
# spamd        This script starts and stops the spamd daemon
#
# chkconfig: 2345 78 32
#
# 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.
. /etc/rc.d/init.d/functions

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

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

RETVAL=0
prog="spamd"

[ -f /usr/bin/$prog ] || exit 0

start() {

	# Lets not run twice
	if [ -f /var/lock/subsys/$prog ]; then
	  RETVAL=1
	  return $RETVAL
	fi

	# Start daemon
	echo -n $"Starting $prog: "
	daemon /usr/bin/$prog -d -c

	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
	return $RETVAL
}

stop() {

	# If we're not running, there's nothing to do
	if [ ! -f /var/lock/subsys/$prog ]; then
	  RETVAL=2
	  return $RETVAL
	fi

	# Stop daemon
	echo -n $"Shutting down $prog: "
	killproc $prog
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
	return $RETVAL
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload)
	stop
	start
	RETVAL=$?
	;;
  condrestart)
	if [ -f /var/lock/subsys/$prog ]; then
	    stop
	    start
	    RETVAL=$?
	fi
	;;
  status)
	status $prog
	RETVAL=$?
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|condrestart|status}"
	exit 1
esac

exit $RETVAL
