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