#!/bin/sh
#
# qmail		This shell script takes care of starting and stopping qmail.
#
# chkconfig:	2345 80 30
#
# description:	Qmail is a Mail Transport Agent, which is the program \
#		that moves mail from one machine to another.


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

# Get network config
. /etc/sysconfig/network

# Get service config
[ -f /etc/sysconfig/qmail ] && . /etc/sysconfig/qmail

# Check that networking is up.
if is_no "${NETWORKING}"; then
	msg_Network_Down Qmail
	exit 1
fi

RETVAL=0

# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/qmail ]; then
		PATH="/var/qmail/bin:$PATH"; export PATH

		# build aliases database
		newaliases
		
		msg_starting qmail
		busy
		qmail-start "`cat /etc/qmail/dot-qmail`" splogger qmail &
		sleep 1

		if ps ax | grep -v grep | grep -q qmail-send
		then
			deltext
			ok
			touch /var/lock/subsys/qmail
		else
			deltext
			fail	  
			RETVAL=1
		fi
	else
		msg_Already_Running qmail
		exit 1
	fi
	;;
  stop)
	# Stop daemons.
	msg_stopping qmail
	killproc qmail-send
	rm -f /var/lock/subsys/qmail
	;;
  queue)
	qmail-qstat
	qmail-qread
	;;
  restart|reload)
  	$0 stop
	$0 start
	;;
  status)
  	status qmail-send
	;;
  *)
	msg_Usage "$0 {start|stop|status|queue|restart|reload}"
	exit 1
esac

exit $RETVAL
