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