#!/bin/sh
#
# This script starts and stops the spampd daemon
#
####   NOTE   #####
#  This is a very old and outdated example!!!
#  Recommend checking the Debian version of spampd.init script,
#  in the /debian branch of the source repository
#  (https://github.com/mpaperno/spampd/tree/debian).
#
# chkconfig: 2345 79 31
#
# description: spampd is a daemon process which uses SpamAssassin to check
#              email messages for SPAM.
# processname: spampd
# pidfile: /var/run/spampd.pid
# config: /etc/sysconfig/spampd
#
### BEGIN INIT INFO
# Provides: spampd
# Default-Start: 2 3 4 5
# Required-Start: $network
# Required-Stop: $network
# Short-Description: Spam Proxy Daemon
# Description: spampd is a daemon process which uses SpamAssassin to check
#              email messages for SPAM.
### END INIT INFO

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

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

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

LISTEN=127.0.0.1:10025
RELAYHOST=127.0.0.1:10026
MAXCHILD=5
OPTIONS="--local-only --tagall"

[ -f /etc/sysconfig/spampd ] && . /etc/sysconfig/spampd

[ -f /usr/sbin/spampd ] || exit 0

RETVAL=0

# See how we were called.
case "$1" in
  start)
	# Start daemon.
	echo -n "Starting spampd: "
	daemon spampd --host=${LISTEN} --relayhost=${RELAYHOST} --children=${MAXCHILD} ${OPTIONS}
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/spampd
	exit $RETVAL
	;;
  stop)
	# Stop daemons.
	echo -n "Shutting down spampd: "
	killproc spampd
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/spampd
	exit $RETVAL
	;;
  restart|reload)
	$0 stop
	$0 start
	;;
  status)
	status spampd
	;;
  condrestart)
	[ -f /var/lock/spampd ] && restart || :
	;;
  *)
	echo "Usage: $0 {start|stop|restart|status}"
	exit 1
esac

exit 0
