1 # Copyright (C) 2010-2016 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18 """The `mailman status` subcommand."""
22 from mailman
import public
23 from mailman
.bin
.master
import WatcherState
, master_state
24 from mailman
.core
.i18n
import _
25 from mailman
.interfaces
.command
import ICLISubCommand
26 from zope
.interface
import implementer
30 @implementer(ICLISubCommand
)
32 """Status of the Mailman system."""
36 def add(self
, parser
, command_parser
):
37 """See `ICLISubCommand`."""
40 def process(self
, args
):
41 """See `ICLISubCommand`."""
42 status
, lock
= master_state()
43 if status
is WatcherState
.none
:
44 message
= _('GNU Mailman is not running')
45 elif status
is WatcherState
.conflict
:
46 hostname
, pid
, tempfile
= lock
.details
47 message
= _('GNU Mailman is running (master pid: $pid)')
48 elif status
is WatcherState
.stale_lock
:
49 hostname
, pid
, tempfile
= lock
.details
50 message
= _('GNU Mailman is stopped (stale pid: $pid)')
52 hostname
, pid
, tempfile
= lock
.details
53 fqdn_name
= socket
.getfqdn() # noqa
54 assert status
is WatcherState
.host_mismatch
, (
55 'Invalid enum value: %s' % status
)
56 message
= _('GNU Mailman is in an unexpected state '
57 '($hostname != $fqdn_name)')