#!/bin/sh
#
# exim      This shell script takes care of starting and stopping
#           exim.
#
# chkconfig: 2345 80 30
# description: exim MTA - a better sendmail replacement
# processname: exim
# config: /etc/exim/exim.conf
# pidfile: /var/run/exim.pid

# First set up a default search path.
export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
WITHOUT_RC_COMPAT=1

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

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

SourceIfNotEmpty /etc/sysconfig/network
SourceIfNotEmpty /etc/sysconfig/exim


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

# check we have an exim to work with
EXIM=/usr/sbin/exim
[ -x ${exim} ] || exit 0
PIDFILE=/var/run/exim.pid
LOCKFILE=/var/lock/subsys/exim
RETVAL=0

# Source exim configuration
if [ -f /etc/sysconfig/exim ]; then
	. /etc/sysconfig/exim
else
	QUEUE_INTERVAL=15m
	DAEMON_MODE=-bd
	OPTIONS=
fi

start()
{
    is_yes "$NETWORKING" || return 0
    exim_aliases
    start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user mail -- $EXIM ${DAEMON_MODE} -q${QUEUE_INTERVAL} ${OPTIONS}
    RETVAL=$?
    return $RETVAL
}

stop()
{
    stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user mail --name exim $EXIM
    RETVAL=$?
    return $RETVAL
}

reload()
{
    msg_reloading exim
    stop_daemon --pidfile "$PIDFILE"  --expect-user mail -HUP $EXIM
    RETVAL=$?
    return $RETVAL
}

restart()
{
    stop
    start
}
# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	# Stop daemons.
	stop
	;;
  status)
	status --pidfile "$PIDFILE" --expect-user mail $EXIM
	RETVAL=$?
	;;
  reconf|reload)
	reload
	;;
  restart)
	restart
	;;
  condstop)
	if [ -e "$LOCKFILE" ]; then
	stop
	fi
	;;
  condrestart)
	if [ -e "$LOCKFILE" ]; then
	restart
	fi
	;;
  condreload)
	if [ -e "$LOCKFILE" ]; then
	reload
	fi
	;;
  *)
	msg_usage "${0##*/} {start|stop|status|reconf|reload|restart|condstop|condrestart|condreload}"
	RETVAL=1
esac

exit $RETVAL
