#! /bin/sh
#
# mailman	starts up the qrunner for mailman

#               Based on skeleton, by those listed below.  Customizations 
#               done by Tollef Fog Heen <tfheen@debian.org>
#
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian GNU/Linux
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version:	@(#)skeleton  1.9.1  08-Apr-2002  miquels@cistron.nl
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/lib/mailman/bin/mailmanctl
PIDFILE=/var/lib/mailman/data/master-qrunner.pid
NAME=mailman
DESC="mailman queue runner"

test -x $DAEMON || exit 0

set -e

case "$1" in
  start)
        if [ "$(/var/lib/mailman/bin/list_lists -b | grep ^mailman$ )" = "" ]; then
            echo "Site list for mailman (usually named mailman) missing"
            echo "Please create it; until then, mailman will refuse to start"
            exit 0
        fi
        $DAEMON -s start
	;;
  stop)
        $DAEMON stop
	;;
  reload)
	#
	#	If the daemon can reload its config files on the fly
	#	for example by sending it SIGHUP, do it here.
	#
	#	If the daemon responds to changes in its config file
	#	directly anyway, make this a do-nothing entry.
	#
	echo -n "Reloading $DESC configuration..."
	$DAEMON restart
  ;;
  restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#
	PID=`cat $PIDFILE 2>/dev/null` || true
	echo -n "Restarting $DESC: $NAME"
        $DAEMON stop
	if test -n "$PID" && kill -0 $PID 2>/dev/null ; then
		echo -n "Waiting "
                for cnt in `seq 1 5`; do
			sleep 1
			kill -0 $PID 2>/dev/null || break
			echo -n "."
		done;
		if kill -0 $PID 2>/dev/null ; then
			echo " Failed"
		else
			echo " Done"
		fi
	fi
        $DAEMON start
	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
