#!/bin/sh
#
# exim      This shell script takes care of starting and stopping
#               exim.
#
# chkconfig: 2345 80 30
# description: Mail Transfer Agent
### BEGIN INIT INFO
# Provides:          exim, exim4, exim4-base, exim4-config, exim4-daemon, mail-transport-agent
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Exim with the exiscan patch
# Description:       Exim with the exiscan patch
### END INIT INFO


BINARY=/usr/sbin/exim
PID=/var/run/exim.pid
EXIM_OPTS=
DAEMON="yes"
QUEUE="15m"
[ "$DAEMON" = yes ] && EXIM_OPTS="$EXIM_OPTS -bd"
[ -n "$QUEUE" ] && EXIM_OPTS="$EXIM_OPTS -q$QUEUE"

KILLALL=/usr/bin/killall

# See how we were called.
case "$1" in
  start)
        # Start daemons.
        echo -n "Starting exim: "
	$BINARY $EXIM_OPTS -oP $PID
        echo
	if [ -e /usr/bin/spamd ]; then /usr/bin/spamd -d -c -m 15 1>/dev/null 2>/dev/null; fi
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down exim: "
        if [ -e $PID ]; then kill `cat $PID`; fi
        echo
	
	if [ -e /usr/bin/spamd ]; then $KILLALL -9 spamd; fi

        ;;
  restart)
        $0 stop
        sleep 3
        $0 start
        ;;
  reload)
        if [ -e $PID ]; then kill -HUP `cat $PID`; fi
        ;;
  condrestart)
	$0 restart
        ;;
  status)
        status exim
        ;;
  *)
        echo "Usage: exim {start|stop|restart|reload|condrestart|status}"
        exit 1
esac

exit 0

