#!/bin/sh
#
# sendmail      This shell script takes care of starting and stopping
#               sendmail.
#
# chkconfig: 2345 80 30
# description: Sendmail is a Mail Transport Agent, which is the program \
#              that moves mail from one machine to another.
# processname: sendmail
# config: /etc/sendmail.cf
# pidfile: /var/run/sendmail.pid

Execute a script to install the support functions

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

Execute a script to set the shell variables for networking

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

Does the sendmail script exist?

# Source sendmail configureation.
if [ -f /etc/sysconfig/sendmail ] ; then
	. /etc/sysconfig/sendmail
else
	DAEMON=yes
	QUEUE=1h
fi

See if the necessary things are available

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

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

Are we starting?

# See how we were called.
case "$1" in
  start)
	# Start daemons.
	echo -n "Starting sendmail: "
	if [ -L `cat /var/run/runlevel.dir`/S*postfix ]; then
		echo_postfix
	else
	daemon /usr/sbin/sendmail $([ "$DAEMON" = yes ] && echo -bd) \
                                  $([ -n "$QUEUE" ] && echo -q$QUEUE)
	fi
	echo
	touch /var/lock/subsys/sendmail
	;;

Or stopping?

  stop)
	# Stop daemons.
	echo -n "Shutting down sendmail: "
        if [ -L `cat /var/run/runlevel.dir`/S*postfix ]; then
                echo_postfix
		killall -9 sendmail >/dev/null 2>&1
        else
	killproc sendmail
	fi
	echo
	rm -f /var/lock/subsys/sendmail
	;;

Or restarting?

  restart)
	$0 stop
	$0 start
	;;

Or checking the status?

  status)
	status sendmail
	;;
  *)
	echo "Usage: sendmail {start|stop|restart|status}"
	exit 1
esac

exit 0