#!/bin/sh
#
# This script starts and stops the spampd daemon
#
# chkconfig: 345 80 20
#
# description: spampd is a daemon process which uses SpamAssassin to check
#              email messages for SPAM.
#
# $Id: spampd.init,v 1.4 2008/10/20 19:36:29 glen Exp $

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

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

# Get service config
[ -f /etc/sysconfig/spampd ] && . /etc/sysconfig/spampd

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network ]; then
		msg_network_down spampd
		exit 1
	fi
else
	exit 0
fi

start() {
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/spampd ]; then
		msg_starting spampd
		daemon spampd --host=$LISTEN --relayhost=$RELAYHOST --children=$MAXCHILD \
			--pid=/var/run/spampd.pid \
			$(is_yes "$TAGALL" && echo --tagall) $SPAMPD_OPTS
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/spampd
	else
		msg_already_running spampd
	fi
}

stop() {
	# Stop daemons.
	if [ -f /var/lock/subsys/spampd ]; then
		# Stop daemons.
		msg_stopping spampd
		killproc --pidfile spampd.pid spampd
		rm -f /var/lock/subsys/spampd
	else
		msg_not_running spampd
	fi
}


condrestart() {
	if [ -f /var/lock/subsys/spampd ]; then
		stop
		start
	else
		msg_not_running spampd
		RETVAL=$1
	fi
}

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

exit $RETVAL
