Blob Blame History Raw
diff -ruN mailman-2.1.12-a/bin/mailmanctl mailman-2.1.12-b/bin/mailmanctl
--- mailman-2.1.12-a/bin/mailmanctl	2009-02-23 22:23:35.000000000 +0100
+++ mailman-2.1.12-b/bin/mailmanctl	2009-07-28 12:19:48.000000000 +0200
@@ -36,7 +36,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:
 
@@ -90,6 +90,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
@@ -190,6 +193,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
@@ -337,13 +386,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
@@ -362,6 +413,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 -ruN mailman-2.1.12-a/misc/mailman.in mailman-2.1.12-b/misc/mailman.in
--- mailman-2.1.12-a/misc/mailman.in	2009-02-23 22:23:35.000000000 +0100
+++ mailman-2.1.12-b/misc/mailman.in	2009-07-28 12:19:48.000000000 +0200
@@ -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