summaryrefslogtreecommitdiff
path: root/src/mailman/commands
diff options
context:
space:
mode:
authorBarry Warsaw2010-12-22 16:38:32 -0500
committerBarry Warsaw2010-12-22 16:38:32 -0500
commit506ddd3af859ebb9d6b8fcf746b286a030a0b927 (patch)
tree9a3bfd5244a8fe54cbe24edd7c30536e01c36bc9 /src/mailman/commands
parentecb3dbbacd350845ae11834ac42c17469811bdfa (diff)
downloadmailman-506ddd3af859ebb9d6b8fcf746b286a030a0b927.tar.gz
mailman-506ddd3af859ebb9d6b8fcf746b286a030a0b927.tar.zst
mailman-506ddd3af859ebb9d6b8fcf746b286a030a0b927.zip
* Start to get rid of pylint; it's more trouble than it's worth and pyflakes
does a pretty good job anyway. * Remove master.get_lock_data() now that flufl.lock 2.1 provides the same detailed information. * Add WatcherState.none to indicate that the master is not running. * Instrument master_state() and acquire_lock_1() for testing, and add unittests. * LBYL for 'bin/mailman start' so that the error message when the master is already running happens in the foreground process and is more user friendly. * Add 'bin/mailman status' to provide master queue runner status on the command line.
Diffstat (limited to 'src/mailman/commands')
-rw-r--r--src/mailman/commands/cli_control.py13
-rw-r--r--src/mailman/commands/cli_status.py68
-rw-r--r--src/mailman/commands/docs/status.txt37
3 files changed, 117 insertions, 1 deletions
diff --git a/src/mailman/commands/cli_control.py b/src/mailman/commands/cli_control.py
index 83432a6e8..2c693621d 100644
--- a/src/mailman/commands/cli_control.py
+++ b/src/mailman/commands/cli_control.py
@@ -36,6 +36,7 @@ import logging
from zope.interface import implements
+from mailman.bin.master import WatcherState, master_state
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
@@ -54,6 +55,7 @@ class Start:
def add(self, parser, command_parser):
"""See `ICLISubCommand`."""
+ self.parser = parser
command_parser.add_argument(
'-f', '--force',
default=False, action='store_true',
@@ -92,6 +94,15 @@ class Start:
def process(self, args):
"""See `ICLISubCommand`."""
+ # Although there's a potential race condition here, it's a better user
+ # experience for the parent process to refuse to start twice, rather
+ # than having it try to start the master, which will error exit.
+ status, lock = master_state()
+ if status is WatcherState.conflict:
+ self.parser.error(_('GNU Mailman is already running'))
+ elif status in (WatcherState.stale_lock, WatcherState.host_mismatch):
+ self.parser.error(_('A previous run of GNU Mailman did not exit '
+ 'cleanly. Try using --force.'))
def log(message):
if not args.quiet:
print message
@@ -152,7 +163,7 @@ def kill_watcher(sig):
class SignalCommand:
"""Common base class for simple, signal sending commands."""
-
+
implements(ICLISubCommand)
name = None
diff --git a/src/mailman/commands/cli_status.py b/src/mailman/commands/cli_status.py
new file mode 100644
index 000000000..abe8cfe3e
--- /dev/null
+++ b/src/mailman/commands/cli_status.py
@@ -0,0 +1,68 @@
+# Copyright (C) 2010 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Module stuff."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'Status',
+ ]
+
+
+import socket
+
+from zope.interface import implements
+
+from mailman.bin.master import WatcherState, master_state
+from mailman.core.i18n import _
+from mailman.interfaces.command import ICLISubCommand
+
+
+
+class Status:
+ """Status of the Mailman system."""
+
+ implements(ICLISubCommand)
+
+ name = 'status'
+
+ def add(self, parser, command_parser):
+ """See `ICLISubCommand`."""
+ pass
+
+ def process(self, args):
+ """See `ICLISubCommand`."""
+ status, lock = master_state()
+ if status is WatcherState.none:
+ message = _('GNU Mailman is not running')
+ elif status is WatcherState.conflict:
+ hostname, pid, tempfile = lock.details
+ message = _('GNU Mailman is running (master pid: $pid)')
+ elif status is WatcherState.stale_lock:
+ hostname, pid, tempfile = lock.details
+ message =_('GNU Mailman is stopped (stale pid: $pid)')
+ else:
+ hostname, pid, tempfile = lock.details
+ fqdn_name = socket.getfqdn()
+ assert status is WatcherState.host_mismatch, (
+ 'Invalid enum value: %s' % status)
+ message = _('GNU Mailman is in an unexpected state '
+ '($hostname != $fqdn_name)')
+ print message
+ return int(status)
diff --git a/src/mailman/commands/docs/status.txt b/src/mailman/commands/docs/status.txt
new file mode 100644
index 000000000..6deb7fdc0
--- /dev/null
+++ b/src/mailman/commands/docs/status.txt
@@ -0,0 +1,37 @@
+==============
+Getting status
+==============
+
+The status of the Mailman master process can be queried from the command line.
+It's clear at this point that nothing is running.
+::
+
+ >>> from mailman.commands.cli_status import Status
+ >>> status = Status()
+
+ >>> class FakeArgs:
+ ... pass
+
+The status is printed to stdout and a status code is returned.
+
+ >>> status.process(FakeArgs)
+ GNU Mailman is not running
+ 0
+
+We can simulate the master queue runner starting up by acquiring its lock.
+
+ >>> from flufl.lock import Lock
+ >>> lock = Lock(config.LOCK_FILE)
+ >>> lock.lock()
+
+Getting the status confirms that the master queue runner is running.
+
+ >>> status.process(FakeArgs)
+ GNU Mailman is running (master pid: ...
+
+We shutdown the master queue runner, and confirm the status.
+
+ >>> lock.unlock()
+ >>> status.process(FakeArgs)
+ GNU Mailman is not running
+ 0