]> git.pld-linux.org Git - packages/mailman.git/blob - mailman-mailmanctl-status.patch
up to 2.1.23
[packages/mailman.git] / mailman-mailmanctl-status.patch
1 --- mailman-2.1.23/bin/mailmanctl~      2016-08-28 14:46:13.000000000 +0300
2 +++ mailman-2.1.23/bin/mailmanctl       2016-08-28 14:47:55.871820256 +0300
3 @@ -35,7 +35,7 @@
4  pid directly.  The `start', `stop', `restart', and `reopen' commands handle
5  everything for you.
6  
7 -Usage: %(PROGRAM)s [options] [ start | stop | restart | reopen ]
8 +Usage: %(PROGRAM)s [options] [ start | stop | restart | reopen | status ]
9  
10  Options:
11  
12 @@ -89,6 +89,9 @@
13  
14      reopen  - This will close all log files, causing them to be re-opened the
15                next time a message is written to them
16 +
17 +    status  - This returns a string indicating the status of the master
18 +              qrunner
19  """
20  
21  import sys
22 @@ -189,6 +192,52 @@
23          return 0
24      return 1
25  
26 +def mailman_status():
27 +    # return status, pid
28 +    #
29 +    # These status values match the /etc/init.d status values
30 +    # (at least on Red Hat), try to return equivalent status if possible
31 +    # status is 0 if running,
32 +    # status is 1 if dead but pid file exists
33 +    # status is 2 if dead but subsys locked
34 +    # status is 3 if stopped (pid returned will be 0)
35 +    #
36 +    #
37 +    # We want any user to be able to query the status and this presents
38 +    # few interesting permission problems and is why we don't use
39 +    # qrunner_state(). The pidfile is only readable by the mailman owner
40 +    # and group, however the lockfile is world readable. So we will
41 +    # get the master pid from the lockfile. We try to determine if the
42 +    # master process exists by sending it a signal. If we don't have
43 +    # permission to signal the process, but the process exists we'll
44 +    # get a EPERM error, if the process does not exist then we'll get
45 +    # a ESRCH error.
46 +
47 +    try:
48 +        hostname, pid, tempfile = get_lock_data()
49 +    except IOError, e:
50 +        if e.errno == errno.ENOENT:
51 +            # Lock file didn't exist, can't be running
52 +            return 3, 0
53 +        else:
54 +            raise
55 +    if hostname <> socket.gethostname():
56 +        # not running on this host
57 +        return 3, 0
58 +    # Find out if the process exists by calling kill with a signal 0.
59 +    try:
60 +        os.kill(pid, 0)
61 +    except OSError, e:
62 +        if e.errno == errno.ESRCH:
63 +            # process does not exist
64 +            return 1, pid
65 +        elif e.errno == errno.EPERM:
66 +            # we don't have permission signal the process but it exists
67 +            return 0, pid
68 +        else:
69 +            raise
70 +    return 0, pid
71 +
72  
73  def acquire_lock_1(force):
74      # Be sure we can acquire the master qrunner lock.  If not, it means some
75 @@ -387,13 +387,15 @@
76          command = COMMASPACE.join(args)
77          usage(1, C_('Bad command: %(command)s'))
78  
79 +    # Handle the commands
80 +    command = args[0].lower()
81 +
82      if checkprivs:
83          check_privs()
84      else:
85 -        print C_('Warning!  You may encounter permission problems.')
86 +        if command != 'status':
87 +            print C_('Warning!  You may encounter permission problems.')
88  
89 -    # Handle the commands
90 -    command = args[0].lower()
91      if command == 'stop':
92          # Sent the master qrunner process a SIGINT, which is equivalent to
93          # giving cron/qrunner a ctrl-c or KeyboardInterrupt.  This will
94 @@ -361,6 +412,14 @@
95          if not quiet:
96              print _('Re-opening all log files')
97          kill_watcher(signal.SIGHUP)
98 +    elif command == 'status':
99 +        status, pid = mailman_status()
100 +        if not quiet:
101 +            if status == 0:
102 +                print _("mailman (pid %(pid)d) is running...")
103 +            else:
104 +                print _("mailman is stopped")
105 +        sys.exit(status)
106      elif command == 'start':
107          # First, complain loudly if there's no site list.
108          check_for_site_list()
109 --- mailman-2.1.20/misc/mailman.in~     2015-03-31 20:21:49.000000000 +0300
110 +++ mailman-2.1.20/misc/mailman.in      2015-05-25 11:22:11.283298992 +0300
111 @@ -37,23 +37,61 @@
112  MAILMANHOME=@prefix@
113  MAILMANCTL=$MAILMANHOME/bin/mailmanctl
114  
115 +# Source function library.
116 +. /etc/rc.d/init.d/functions
117 +
118 +RETVAL=0
119 +prog="mailman"
120 +
121 +start() {
122 +    msg_starting "$prog"
123 +    daemon $PYTHON $MAILMANCTL -s -q start
124 +    RETVAL=$?
125 +    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
126 +}
127 +
128 +stop() {
129 +    msg_stopping "$prog"
130 +    daemon $PYTHON $MAILMANCTL -q stop
131 +    RETVAL=$?
132 +    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
133 +}
134 +
135 +restart() {
136 +    stop
137 +    start
138 +    RETVAL=$?
139 +}
140 +
141 +
142  case "$1" in
143  'start')
144 -    #rm -f $MAILMANHOME/locks/*
145 -    $PYTHON $MAILMANCTL -s -q start
146 +    start
147      ;;
148  
149  'stop')
150 -    $PYTHON $MAILMANCTL -q stop
151 +    stop
152      ;;
153  
154  'restart')
155 -    $PYTHON $MAILMANCTL -q restart
156 +    restart
157      ;;
158  
159  'reopen')
160      $PYTHON $MAILMANCTL -q reopen
161      ;;
162  
163 +'condrestart')
164 +    $PYTHON $MAILMANCTL -q -u status
165 +    retval=$?
166 +    if [ $retval -eq 0 ]; then
167 +               restart
168 +    fi
169 +    ;;
170 +
171 +'status')
172 +    $PYTHON $MAILMANCTL -u status
173 +    RETVAL=$?
174 +
175  esac
176 -exit 0
177 +exit $RETVAL
This page took 0.124957 seconds and 3 git commands to generate.