diff -r -u mailman-2.1.5.orig/bin/mailmanctl mailman-2.1.5/bin/mailmanctl --- mailman-2.1.5.orig/bin/mailmanctl 2004-02-03 17:26:08.000000000 -0500 +++ mailman-2.1.5/bin/mailmanctl 2004-09-10 18:23:34.000000000 -0400 @@ -35,7 +35,7 @@ pid directly. The `start', `stop', `restart', and `reopen' commands handle everything for you. -Usage: %(PROGRAM)s [options] [ start | stop | restart | reopen ] +Usage: %(PROGRAM)s [options] [ start | stop | restart | reopen | status ] Options: @@ -89,6 +89,9 @@ reopen - This will close all log files, causing them to be re-opened the next time a message is written to them + + status - This returns a string indicating the status of the master + qrunner """ import sys @@ -189,6 +192,52 @@ return 0 return 1 +def mailman_status(): + # return status, pid + # + # These status values match the /etc/init.d status values + # (at least on Red Hat), try to return equivalent status if possible + # status is 0 if running, + # status is 1 if dead but pid file exists + # status is 2 if dead but subsys locked + # status is 3 if stopped (pid returned will be 0) + # + # + # We want any user to be able to query the status and this presents + # few interesting permission problems and is why we don't use + # qrunner_state(). The pidfile is only readable by the mailman owner + # and group, however the lockfile is world readable. So we will + # get the master pid from the lockfile. We try to determine if the + # master process exists by sending it a signal. If we don't have + # permission to signal the process, but the process exists we'll + # get a EPERM error, if the process does not exist then we'll get + # a ESRCH error. + + try: + hostname, pid, tempfile = get_lock_data() + except IOError, e: + if e.errno == errno.ENOENT: + # Lock file didn't exist, can't be running + return 3, 0 + else: + raise + if hostname <> socket.gethostname(): + # not running on this host + return 3, 0 + # Find out if the process exists by calling kill with a signal 0. + try: + os.kill(pid, 0) + except OSError, e: + if e.errno == errno.ESRCH: + # process does not exist + return 1, pid + elif e.errno == errno.EPERM: + # we don't have permission signal the process but it exists + return 0, pid + else: + raise + return 0, pid + def acquire_lock_1(force): # Be sure we can acquire the master qrunner lock. If not, it means some @@ -336,13 +385,15 @@ command = COMMASPACE.join(args) usage(1, _('Bad command: %(command)s')) + command = args[0].lower() + if checkprivs: check_privs() else: - print _('Warning! You may encounter permission problems.') + if command != 'status': + print _('Warning! You may encounter permission problems.') # Handle the commands - command = args[0].lower() if command == 'stop': # Sent the master qrunner process a SIGINT, which is equivalent to # giving cron/qrunner a ctrl-c or KeyboardInterrupt. This will @@ -361,6 +412,14 @@ if not quiet: print _('Re-opening all log files') kill_watcher(signal.SIGHUP) + elif command == 'status': + status, pid = mailman_status() + if not quiet: + if status == 0: + print _("mailman (pid %(pid)d) is running...") + else: + print _("mailman is stopped") + sys.exit(status) elif command == 'start': # First, complain loudly if there's no site list. check_for_site_list() diff -u -r mailman-2.1.5.orig/misc/mailman.in mailman-2.1.5/misc/mailman.in --- mailman-2.1.5.orig/misc/mailman.in 2003-09-25 18:13:26.000000000 -0400 +++ mailman-2.1.5/misc/mailman.in 2005-02-15 10:48:26.445983000 -0500 @@ -36,19 +36,70 @@ MAILMANHOME=@prefix@ MAILMANCTL=$MAILMANHOME/bin/mailmanctl +# Source function library. +. /etc/rc.d/init.d/functions + +RETVAL=0 +prog="mailman" + +function start() +{ + echo -n $"Starting $prog: " + daemon $PYTHON $MAILMANCTL -s -q start + RETVAL=$? + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog + echo + return $RETVAL +} + +function stop() +{ + echo -n $"Shutting down $prog: " + daemon $PYTHON $MAILMANCTL -q stop + RETVAL=$? + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog + echo + return $RETVAL +} + +function restart() +{ + stop + start + RETVAL=$? + return $RETVAL +} + case "$1" in 'start') - #rm -f $MAILMANHOME/locks/* - $PYTHON $MAILMANCTL -s -q start + start + RETVAL=$? ;; 'stop') - $PYTHON $MAILMANCTL -q stop + stop + RETVAL=$? ;; 'restart') - $PYTHON $MAILMANCTL -q restart + restart + RETVAL=$? + ;; + +'condrestart') + $PYTHON $MAILMANCTL -q -u status + retval=$? + if [ $retval -eq 0 ] + then + restart + RETVAL=$? + fi + ;; + +'status') + $PYTHON $MAILMANCTL -u status + RETVAL=$? ;; esac -exit 0 +exit $RETVAL