#!/bin/sh
#
# athena-sendmail:	Start the Athena sendmail service.
#
# chkconfig: 2345 80 30
# description: Sendmail startup.
# processname: sendmail
# pidfile: /var/run/sendmail.pid
#
# config: /etc/sysconfig/network
# config: /etc/sendmail.cf

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

. /etc/sysconfig/network
. /etc/athena/rc.conf

PATH=/etc/athena:/bin/athena:/usr/athena/bin:$PATH

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

[ -f /etc/athena/xntpd ] || exit 0

[ "$SENDMAIL" = true ] || exit 0

RETVAL=0

# See how we were called
case "$1" in
  start)
	echo -n "Starting Athena sendmail: "

	# Remove temporary files
	if [ -d /var/spool/mqueue ]; then
		(cd /var/spool/mqueue && rm -f nf* lf*)
	fi
	
	# Sync aliases database
	/usr/sbin/sendmail -bi > /dev/null

	daemon sendmail -bd -q1h
	RETVAL=$?

	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/athena-sendmail
	;;

  stop)
	echo -n "Stopping Athena sendmail: "
	killproc sendmail
	RETVAL=$?

	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/athena-sendmail
	;;

  status)
	status sendmail
	RETVAL=$?
	;;

  restart)
	$0 stop
	$0 start
	RETVAL=$?
	;;

  reload)
	killall -HUP sendmail
	RETVAL=$?
	;;

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

exit $RETVAL
