|
|
5c2a97 |
diff --git a/bin/mailmanctl b/bin/mailmanctl
|
|
|
5c2a97 |
index fa14a2c..e291df1 100644
|
|
|
5c2a97 |
--- a/bin/mailmanctl
|
|
|
5c2a97 |
+++ b/bin/mailmanctl
|
|
|
5c2a97 |
@@ -36,7 +36,7 @@ in the file data/master-qrunner.pid but you normally don't need to use this
|
|
|
5c2a97 |
pid directly. The `start', `stop', `restart', and `reopen' commands handle
|
|
|
5c2a97 |
everything for you.
|
|
|
5c2a97 |
|
|
|
5c2a97 |
-Usage: %(PROGRAM)s [options] [ start | stop | restart | reopen ]
|
|
|
5c2a97 |
+Usage: %(PROGRAM)s [options] [ start | stop | restart | reopen | status ]
|
|
|
5c2a97 |
|
|
|
5c2a97 |
Options:
|
|
|
5c2a97 |
|
|
|
5c2a97 |
@@ -90,6 +90,9 @@ Commands:
|
|
|
5c2a97 |
|
|
|
5c2a97 |
reopen - This will close all log files, causing them to be re-opened the
|
|
|
5c2a97 |
next time a message is written to them
|
|
|
5c2a97 |
+
|
|
|
5c2a97 |
+ status - This returns a string indicating the status of the master
|
|
|
5c2a97 |
+ qrunner
|
|
|
5c2a97 |
"""
|
|
|
5c2a97 |
|
|
|
5c2a97 |
import sys
|
|
|
5c2a97 |
@@ -190,6 +193,52 @@ def qrunner_state():
|
|
|
5c2a97 |
return 0
|
|
|
5c2a97 |
return 1
|
|
|
5c2a97 |
|
|
|
5c2a97 |
+def mailman_status():
|
|
|
5c2a97 |
+ # return status, pid
|
|
|
5c2a97 |
+ #
|
|
|
5c2a97 |
+ # These status values match the /etc/init.d status values
|
|
|
5c2a97 |
+ # (at least on Red Hat), try to return equivalent status if possible
|
|
|
5c2a97 |
+ # status is 0 if running,
|
|
|
5c2a97 |
+ # status is 1 if dead but pid file exists
|
|
|
5c2a97 |
+ # status is 2 if dead but subsys locked
|
|
|
5c2a97 |
+ # status is 3 if stopped (pid returned will be 0)
|
|
|
5c2a97 |
+ #
|
|
|
5c2a97 |
+ #
|
|
|
5c2a97 |
+ # We want any user to be able to query the status and this presents
|
|
|
5c2a97 |
+ # few interesting permission problems and is why we don't use
|
|
|
5c2a97 |
+ # qrunner_state(). The pidfile is only readable by the mailman owner
|
|
|
5c2a97 |
+ # and group, however the lockfile is world readable. So we will
|
|
|
5c2a97 |
+ # get the master pid from the lockfile. We try to determine if the
|
|
|
5c2a97 |
+ # master process exists by sending it a signal. If we don't have
|
|
|
5c2a97 |
+ # permission to signal the process, but the process exists we'll
|
|
|
5c2a97 |
+ # get a EPERM error, if the process does not exist then we'll get
|
|
|
5c2a97 |
+ # a ESRCH error.
|
|
|
5c2a97 |
+
|
|
|
5c2a97 |
+ try:
|
|
|
5c2a97 |
+ hostname, pid, tempfile = get_lock_data()
|
|
|
5c2a97 |
+ except IOError, e:
|
|
|
5c2a97 |
+ if e.errno == errno.ENOENT:
|
|
|
5c2a97 |
+ # Lock file didn't exist, can't be running
|
|
|
5c2a97 |
+ return 3, 0
|
|
|
5c2a97 |
+ else:
|
|
|
5c2a97 |
+ raise
|
|
|
5c2a97 |
+ if hostname <> socket.gethostname():
|
|
|
5c2a97 |
+ # not running on this host
|
|
|
5c2a97 |
+ return 3, 0
|
|
|
5c2a97 |
+ # Find out if the process exists by calling kill with a signal 0.
|
|
|
5c2a97 |
+ try:
|
|
|
5c2a97 |
+ os.kill(pid, 0)
|
|
|
5c2a97 |
+ except OSError, e:
|
|
|
5c2a97 |
+ if e.errno == errno.ESRCH:
|
|
|
5c2a97 |
+ # process does not exist
|
|
|
5c2a97 |
+ return 1, pid
|
|
|
5c2a97 |
+ elif e.errno == errno.EPERM:
|
|
|
5c2a97 |
+ # we don't have permission signal the process but it exists
|
|
|
5c2a97 |
+ return 0, pid
|
|
|
5c2a97 |
+ else:
|
|
|
5c2a97 |
+ raise
|
|
|
5c2a97 |
+ return 0, pid
|
|
|
5c2a97 |
+
|
|
|
5c2a97 |
|
|
|
5c2a97 |
def acquire_lock_1(force):
|
|
|
5c2a97 |
# Be sure we can acquire the master qrunner lock. If not, it means some
|
|
|
5c2a97 |
@@ -338,13 +387,15 @@ def main():
|
|
|
5c2a97 |
command = COMMASPACE.join(args)
|
|
|
5c2a97 |
usage(1, C_('Bad command: %(command)s'))
|
|
|
5c2a97 |
|
|
|
5c2a97 |
+ command = args[0].lower()
|
|
|
5c2a97 |
+
|
|
|
5c2a97 |
if checkprivs:
|
|
|
5c2a97 |
check_privs()
|
|
|
5c2a97 |
else:
|
|
|
5c2a97 |
- print C_('Warning! You may encounter permission problems.')
|
|
|
5c2a97 |
+ if command != 'status':
|
|
|
5c2a97 |
+ print C_('Warning! You may encounter permission problems.')
|
|
|
5c2a97 |
|
|
|
5c2a97 |
# Handle the commands
|
|
|
5c2a97 |
- command = args[0].lower()
|
|
|
5c2a97 |
if command == 'stop':
|
|
|
5c2a97 |
# Sent the master qrunner process a SIGINT, which is equivalent to
|
|
|
5c2a97 |
# giving cron/qrunner a ctrl-c or KeyboardInterrupt. This will
|
|
|
5c2a97 |
@@ -363,6 +414,14 @@ def main():
|
|
|
5c2a97 |
if not quiet:
|
|
|
5c2a97 |
print C_('Re-opening all log files')
|
|
|
5c2a97 |
kill_watcher(signal.SIGHUP)
|
|
|
5c2a97 |
+ elif command == 'status':
|
|
|
5c2a97 |
+ status, pid = mailman_status()
|
|
|
5c2a97 |
+ if not quiet:
|
|
|
5c2a97 |
+ if status == 0:
|
|
|
5c2a97 |
+ print C_("mailman (pid %(pid)d) is running...")
|
|
|
5c2a97 |
+ else:
|
|
|
5c2a97 |
+ print C_("mailman is stopped")
|
|
|
5c2a97 |
+ sys.exit(status)
|
|
|
5c2a97 |
elif command == 'start':
|
|
|
5c2a97 |
# First, complain loudly if there's no site list.
|
|
|
5c2a97 |
check_for_site_list()
|