#!/bin/sh
# qmail This shell script helps you stop and start qmail temporarily.
#
# 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

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

svcget() {
	local svc
	for s in `ls -d "$@" 2>/dev/null`; do
		svc="$svc $s"
	done
	echo $svc
}

RETVAL=0

# with daemontools we have no consistncey with subsys locking, so here's none.
# maybe it's todo, if it's really needed, but now it seems it's irrelevant.

# See how we were called.
case "$1" in
start)
	svc=$(svcget /service/qmail-{smtpd,send,qmqpd,qmtpd})
	echo "Starting qmail mta ($svc)..."
	svc -u $svc

	svc=$(svcget /service/qmail-{smtpd,send,qmqpd,qmtpd}/log)
	echo "Starting qmail mta logging ($svc) ..."
	svc -u $svc
;;

stop)
    svc=$(svcget /service/qmail-{smtpd,send,qmqpd,qmtpd})
    echo "Stopping qmail mta ($svc)..."
    svc -d $svc

    svc=$(svcget /service/qmail-{smtpd,send,qmqpd,qmtpd}/log)
    echo "Stopping qmail mta logging ($svc)..."
    svc -d $svc
;;

restart)
	$0 stop
	$0 start
;;

reload)
    echo "Reloading 'locals' and 'virtualdomains' control files."
    svc -h /service/qmail-send
;;

queue)
	qmail-qstat
	qmail-qread
;;

*)
	msg_usage "$0 {start|stop|restart|reload|status|queue}"
	exit 3
esac

exit $RETVAL
