Update of /cvsroot/mailman/mailman3/bin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28378/bin

Modified Files:
        mailmanctl qrunner 
Log Message:
Updates for the new configuration regime.


Index: mailmanctl
===================================================================
RCS file: /cvsroot/mailman/mailman3/bin/mailmanctl,v
retrieving revision 3.0
retrieving revision 3.1
diff -u -d -r3.0 -r3.1
--- mailmanctl  29 Mar 2004 05:18:49 -0000      3.0
+++ mailmanctl  20 Apr 2004 04:11:36 -0000      3.1
@@ -24,22 +24,23 @@
 import signal
 import socket
 import logging
+import traceback
 from optparse import OptionParser
 
 import paths
-from mailman.config import configure, configuration
-from mailman.config.logs import initlogs, rotateLogs
+from mailman.config import configuration
 from mailman.config.versions import version
 from mailman.i18n import _
 
 
 
 def kill_watcher(sig):
+    qconf = configuration.qrunner
     try:
-        fp = open(configuration.mailman.pidfile)
+        fp = open(configuration.qrunner.pidfile)
     except IOError, e:
         if e.errno <> errno.ENOENT: raise
-        print >> sys.stderr, _('No pid file: $config.pidfile')
+        print >> sys.stderr, _('No pid file: $qconf.pidfile')
         print >> sys.stderr, _('Is Mailman even running?')
         return
     try:
@@ -50,7 +51,7 @@
         pid = int(pidstr.strip())
     except ValueError:
         # For i18n convenience
-        print >> sys.stderr, _('PID unparseable in: $config.pidfile')
+        print >> sys.stderr, _('PID unparseable: $qconf.pidfile')
         print >> sys.stderr, _('pid: $pid')
         print >> sys.stderr, _('Is Mailman even running?')
         return
@@ -62,12 +63,12 @@
         print >> sys.stderr, _('No child with pid: $pid')
         print >> sys.stderr, e
         print >> sys.stderr, _('Stale pid file removed.')
-        os.unlink(config.pidfile)
+        os.unlink(qconf.pidfile)
 
 
 
 def read_pid():
-    fp = open(configuration.mailman.pidfile)
+    fp = open(configuration.qrunner.pidfile)
     try:
         pid = int(fp.read().strip())
     finally:
@@ -89,7 +90,7 @@
 def acquire_lock_1(force):
     flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
     try:
-        return os.open(configuration.mailman.pidfile, flags, 0770)
+        return os.open(configuration.qrunner.pidfile, flags, 0770)
     except OSError, e:
         if e.errno <> errno.EEXIST: raise
         # The file already exists, meaning the watcher could already be
@@ -98,7 +99,7 @@
         # higher ups can catch it and print an error message.
         if force:
             print >> sys.stderr, _('Removing stale pid file')
-            os.unlink(configuration.mailman.pidfile)
+            os.unlink(configuration.qrunner.pidfile)
             return acquire_lock_1(force=False)
         else:
             raise
@@ -133,9 +134,9 @@
     # Craft the command line arguments for the exec() call.
     args = ['--runner=%s:%d' % (qrname, slice)]
     args.extend(['-s', '-l'])
-    args.extend(['-C', options.configdir])
-    qrexe = os.path.join(configuration.dirs.bindir, 'qrunner')
-    pyexe = configuration.mailman.pythonexe
+    args.extend(['-C', options.configfile])
+    qrexe = os.path.join(configuration.layout.bindir, 'qrunner')
+    pyexe = configuration.qrunner.pythonexe
     # mm_cfg.PYTHON, which is the absolute path to the Python interpreter,
     # must be given as argv[0] due to Python's library search algorithm.
     log.debug('mailmanctl starting qrunner: %s %s', qrexe, args)
@@ -146,34 +147,15 @@
 
 def start_all_runners():
     kids = {}
-    for qrname, qrclass, count in configuration.smtp.queue:
-        for slice in range(count):
-            # queue runner name, slice, restart count
-            info = (qrname, slice, 0)
-            pid = start_runner(qrname, slice)
+    for q in configuration.qrunner.queue:
+        for i in range(q.count):
+            info = (q.qrunner, i, 0)
+            pid = start_runner(q.qrunner, i)
             kids[pid] = info
     return kids
 
 
 
-def checkprivs():
-    uid, uname = configuration.mailman.userid
-    gid, gname = configuration.mailman.groupid
-    # If we're running as root (uid == 0), coerce the uid and gid to that
-    # which Mailman was configured for, and refuse to run if we didn't coerce
-    # the uid/gid.
-    myuid = os.getuid()
-    if myuid == 0:
-        os.setuid(uid)
-        os.setgid(gid)
-    elif myuid <> uid:
-        parser.print_help()
-        print
-        print _('Run this program as root or use -u.')
-        sys.exit(1)
-
-
-
 def loop_forever(kids):
     try:
         while True:
@@ -210,10 +192,10 @@
             # See if we've reached the maximum number of allowable restarts
             if exitstatus <> signal.SIGINT:
                 restarts += 1
-            if restarts > configuration.smtp.max_restarts:
+            if restarts > configuration.qrunner.max_restarts:
                 log.info("""\
 Qrunner %s reached maximum restart limit of %d, not restarting.""",
-                         qrname, configuration.smtp.max_restarts)
+                         qrname, configuration.qrunner.max_restarts)
                 restarting = ''
             # Now perhaps restart the process unless it exited with a SIGTERM
             # or we aren't restarting.
@@ -243,7 +225,7 @@
                     raise
                 continue
         # And now remove our pidfile
-        os.unlink(configuration.mailman.pidfile)
+        os.unlink(configuration.qrunner.pidfile)
 
 
 
@@ -284,35 +266,15 @@
 
     reopen  - This will close all log files, causing them to be re-opened the
               next time a message is written to them""")
-    parser.add_option('-C', '--configdir', metavar='DIR', dest='configdir',
+    parser.add_option('-C', '--configfile', metavar='FILE',
                       help=_("""\
-Directory containing the Mailman configuration files.  If this option is not
-given, Mailman will search for a 'mmconfig' directory containing the
-mailman.xml file."""))
+The configuration file for Mailman's qrunners."""))
     parser.add_option('-n', '--no-restart', dest='restart', default=True,
                       action='store_false', help=_("""\
 Don't restart the qrunners when they exit because of an error or a
 SIGINT.  They are never restarted if they exit in response to a
 SIGTERM.  Use this only for debugging.  Only useful if the 'start'
 command is given."""))
-    parser.add_option('-u', '--run-as-user', default=True,
-                      dest='checkprivs', action='store_false',
-                      help=_("""\
-Normally, this script will refuse to run if the user id and group id
-are not set to the 'mailman' user and group (as defined when you
-configured Mailman).  If run as root, this script will change to this
-user and group before the check is made.
-
-This can be inconvenient for testing and debugging purposes, so the -u
-flag means that the step that sets and checks the uid/gid is skipped,
-and the program is run as the current user and group.  This flag is
-not recommended for normal production environments.
-
-Note though, that if you run with -u and are not in the 'mailman' group,
-you may have permission problems, such as begin unable to delete a
-list's archives through the web.  Tough luck!
-
-This option is only useful with the 'start' command."""))
     parser.add_option('-s', '--stale-lock-cleanup', default=False,
                       dest='force', action='store_true',
                       help=_("""\
@@ -337,12 +299,12 @@
         sys.exit(1)
     # We must have a config directory.  If one wasn't given, look for
     # ../mmconfig
-    if opts.configdir is None:
+    if opts.configfile is None:
         here = os.path.abspath(os.path.dirname(__file__))
-        parent = os.path.normpath(os.path.join(here, '../mmconfig'))
+        parent = os.path.normpath(os.path.join(here, '..', 'etc'))
         cfile = os.path.join(parent, 'mailman.conf')
         if os.path.exists(cfile):
-            opts.configdir = parent
+            opts.configfile = cfile
         else:
             parser.print_help()
             print
@@ -351,7 +313,6 @@
     return opts, parser, args[0]
 
 
-
 
 def main(command):
     if command == 'stop':
@@ -373,10 +334,6 @@
             print _('Re-opening all log files')
         kill_watcher(signal.SIGHUP)
     elif command == 'start':
-        if options.checkprivs:
-            checkprivs()
-        else:
-            print _('Warning!  You may encounter permission problems.')
         # Create and start all the child processes, consisting of the qrunner
         # processes and the master process watcher.
         #
@@ -403,19 +360,21 @@
         print >> fp, os.getpid()
         fp.flush()
         fp.close()
-        # Close stdin, stdout, and stderr and point them to /dev/null
-        os.close(0)
-        sys.stdin = sys.__stdin__ = open('/dev/null')
-        os.close(1)
-        sys.stdout = sys.__stdout__ = open('/dev/null', 'w')
-        os.close(2)
-        sys.stderr = sys.__stderr__ = open('/dev/null', 'w')
+        # Close stdin, stdout, and stderr and point them at /dev/null.
+        # BAW: Actually, we want stdout and stderr to point at the
+        # mailman.error log file at critical level.
+##        os.close(0)
+##        sys.stdin = sys.__stdin__ = open('/dev/null')
+##        os.close(1)
+##        sys.stdout = sys.__stdout__ = open('/dev/null', 'w')
+##        os.close(2)
+##        sys.stderr = sys.__stderr__ = open('/dev/null', 'w')
         # Create a new session and become the session leader, but since we
         # won't be opening any terminal devices, don't do the ultra-paranoid
         # suggestion of doing a second fork after the setsid() call.
         os.setsid()
         # Instead of cd'ing to root, cd to the Mailman installation home
-        os.chdir(configuration.dirs.basedir)
+        os.chdir(configuration.layout.basedir)
         # Clear our file mode creation umask
         os.umask(0)
         # I don't think we have any unneeded file descriptors.
@@ -428,9 +387,10 @@
         # Set up a SIGHUP handler that will propagate to the qrunner children.
         # This will tell them to close and reopen their log files
         def sighup_handler(signum, frame):
-            # Closing our syslog will cause it to be re-opened at the next log
-            # print output.
-            rotateLogs()
+            # BAW: Rotating logs on SIGHUP doesn't work right so for now, it's
+            # disabled.  There's a bit of a impedence mismatch with the
+            # ZConfig-based log component.  Gotta work this out.
+            #rotateLogs()
             for pid in kids.keys():
                 os.kill(pid, signal.SIGHUP)
             # And just to tweak things...
@@ -462,8 +422,7 @@
 
 if __name__ == '__main__':
     options, parser, command = parseargs()
-    configure(options.configdir)
-    initlogs()
+    configuration.configure(options.configfile)
     try:
         log = logging.getLogger('mailman.queues')
         main(command)

Index: qrunner
===================================================================
RCS file: /cvsroot/mailman/mailman3/bin/qrunner,v
retrieving revision 3.0
retrieving revision 3.1
diff -u -d -r3.0 -r3.1
--- qrunner     29 Mar 2004 05:18:49 -0000      3.0
+++ qrunner     20 Apr 2004 04:11:36 -0000      3.1
@@ -1,6 +1,6 @@
 #! /usr/bin/env python
 
-# Copyright (C) 2003 Barry A. Warsaw
+# Copyright (C) 2004 Barry A. Warsaw
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -27,8 +27,7 @@
 
 import paths
 from mailman import startup
-from mailman.config import configure, configuration
-from mailman.config.logs import rotateLogs
+from mailman.config import configuration
 from mailman.config.versions import version
 from mailman.i18n import _
 
@@ -46,7 +45,7 @@
         else:
             raise
     qrclass = getattr(sys.modules[modulename],
-                      configuration.smtp.qrunners[qrname][0])
+                      configuration.qrunner.qrunners[qrname][0])
     if not options.loop:
         # Subclass to hack in the setting of the stop flag in _doperiodic()
         class Once(qrclass):
@@ -114,7 +113,9 @@
     # SIGHUP just tells us to close our log files.  They'll be
     # automatically reopened at the next log print :)
     def sighup_handler(signum, frame):
-        rotateLogs()
+        # BAW: This doesn't quite match what ZConfig's log files give us.  We
+        # need to deal with rotating the log files.
+        #rotateLogs()
         log.info('%s qrunner caught SIGHUP.  Rotating logs.', loop.name())
 
     signal.signal(signal.SIGHUP, sighup_handler)
@@ -136,11 +137,9 @@
 
 -r is required unless --listall or -h is given, and it must be one of the
 names displayed by the --listall switch.""")
-    parser.add_option('-C', '--configdir', metavar='DIR', dest='configdir',
+    parser.add_option('-C', '--configfile', metavar='FILE',
                       help=_("""\
-Directory containing the Mailman configuration files.  If this option is not
-given, Mailman will search for a 'mmconfig' directory containing the
-mailman.xml file."""))
+The configuration file for Mailman's qrunners."""))
     parser.add_option('--listall', default=False, action='store_true',
                       help=_("""List all the available qrunners."""))
     parser.add_option('-r', '--runner', default=[], action='append',
@@ -173,12 +172,12 @@
         sys.exit(1)
     # We must have a config directory.  If one wasn't given, look for
     # ../mmconfig
-    if opts.configdir is None:
+    if opts.configfile is None:
         here = os.path.abspath(os.path.dirname(__file__))
-        parent = os.path.normpath(os.path.join(here, '../mmconfig'))
+        parent = os.path.normpath(os.path.join(here, '..', 'etc'))
         cfile = os.path.join(parent, 'mailman.conf')
         if os.path.exists(cfile):
-            opts.configdir = parent
+            opts.configfile = cfile
         else:
             parser.print_help()
             print
@@ -206,8 +205,8 @@
     # Handle list all
     if options.listall:
         print _('Available qrunners (queue, class, count):')
-        for qrname, qrclass, qrcount in configuration.smtp.queue:
-            print '   %10s %15s %s' % (qrname, qrclass, qrcount)
+        for q in configuration.qrunner.queue:
+            print '   %10s %15s %s' % (q.qrunner, q.qclass, q.count)
         sys.exit(0)
     # Fast track for one infinite runner
     if len(options.runners) == 1 and options.loop:
@@ -222,9 +221,9 @@
     else:
         # Anything else we have to handle a bit more specially
         qrunners = []
-        for qrname, slice in options.runners:
+        for qrname, i in options.runners:
             qrclass = configuration.qrunners[qrname][0]
-            qrunner = make_qrunner(qrname, slice, True)
+            qrunner = make_qrunner(qrname, i, True)
             qrunners.append(qrunner)
         # This class is used to manage the main loop
         loop = StoppableLoop()
@@ -248,11 +247,8 @@
 
 if __name__ == '__main__':
     options, parser = parseargs()
-    configure(options.configdir)
+    configuration.configure(options.configfile)
     startup.startup()
-    try:
-        log = logging.getLogger('mailman.queues')
-        status = main()
-        sys.exit(status)
-    finally:
-        startup.shutdown()
+    log = logging.getLogger('mailman.queues')
+    status = main()
+    sys.exit(status)


_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to