[Zodb-checkins] SVN: ZODB/trunk/src/ Bug fixed

Jim Fulton jim at zope.com
Fri Sep 24 13:42:12 EDT 2010


Log message for revision 116788:
  Bug fixed
  
  - Logrotation/repoening via a SIGUSR2 signal wasn't implemented.
    (https://bugs.launchpad.net/zodb/+bug/143600)
  
  Needs windows test.
  

Changed:
  U   ZODB/trunk/src/CHANGES.txt
  U   ZODB/trunk/src/ZEO/runzeo.py
  U   ZODB/trunk/src/ZEO/tests/testZEO.py

-=-
Modified: ZODB/trunk/src/CHANGES.txt
===================================================================
--- ZODB/trunk/src/CHANGES.txt	2010-09-24 16:09:02 UTC (rev 116787)
+++ ZODB/trunk/src/CHANGES.txt	2010-09-24 17:42:12 UTC (rev 116788)
@@ -41,6 +41,11 @@
 - Object ids created in a savepoint that is rolled back wren't being
   reused. (https://bugs.launchpad.net/zodb/+bug/588389)
 
+- Logrotation/repoening via a SIGUSR2 signal wasn't implemented.
+  (https://bugs.launchpad.net/zodb/+bug/143600)
+
+  (Untested on windows.)
+
 3.10.0b6 (2010-09-08)
 =====================
 

Modified: ZODB/trunk/src/ZEO/runzeo.py
===================================================================
--- ZODB/trunk/src/ZEO/runzeo.py	2010-09-24 16:09:02 UTC (rev 116787)
+++ ZODB/trunk/src/ZEO/runzeo.py	2010-09-24 17:42:12 UTC (rev 116788)
@@ -269,11 +269,31 @@
         sys.exit(1)
 
     def handle_sigusr2(self):
-        # TODO: this used to reinitialize zLOG. How do I achieve
-        # the same effect with Python's logging package?
-        # Should we restart as with SIGHUP?
-        log("received SIGUSR2, but it was not handled!", level=logging.WARNING)
+        # log rotation signal - do the same as Zope 2.7/2.8...
+        if self.options.config_logger is None or os.name not in ("posix", "nt"):
+            log("received SIGUSR2, but it was not handled!", 
+                level=logging.WARNING)
+            return
 
+        loggers = [self.options.config_logger]
+
+        if os.name == "posix":
+            for l in loggers:
+                l.reopen()
+            log("Log files reopened successfully", level=logging.INFO)
+        else: # nt - same rotation code as in Zope's Signals/Signals.py
+            for l in loggers:
+                for f in l.handler_factories:
+                    handler = f()
+                    if hasattr(handler, 'rotate') and callable(handler.rotate):
+                        handler.rotate()
+            log("Log files rotation complete", level=logging.INFO)
+
+
+
+
+
+
     def close_storages(self):
         for name, storage in self.storages.items():
             log("closing storage %r" % name)

Modified: ZODB/trunk/src/ZEO/tests/testZEO.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/testZEO.py	2010-09-24 16:09:02 UTC (rev 116787)
+++ ZODB/trunk/src/ZEO/tests/testZEO.py	2010-09-24 17:42:12 UTC (rev 116788)
@@ -1476,6 +1476,66 @@
 
     """
 
+
+script_template = """
+import sys
+sys.path[:] = %(path)r
+
+%(src)s
+
+"""
+def generate_script(name, src):
+    open(name, 'w').write(script_template % dict(
+        exe=sys.executable,
+        path=sys.path,
+        src=src,
+        ))
+
+def runzeo_logrotate_on_sigusr2():
+    """
+    >>> port = get_port()
+    >>> open('c', 'w').write('''
+    ... <zeo>
+    ...    address %s
+    ... </zeo>
+    ... <mappingstorage>
+    ... </mappingstorage>
+    ... <eventlog>
+    ...    <logfile>
+    ...       path l
+    ...    </logfile>
+    ... </eventlog>
+    ... ''' % port)
+    >>> generate_script('s', '''
+    ... import ZEO.runzeo
+    ... ZEO.runzeo.main()
+    ... ''')
+    >>> import subprocess, signal
+    >>> p = subprocess.Popen([sys.executable, 's', '-Cc'], close_fds=True)
+    >>> wait_until('started',
+    ...   lambda : os.path.exists('l') and ('listening on' in open('l').read())
+    ...   )
+
+    >>> oldlog = open('l').read()
+    >>> os.rename('l', 'o')
+    >>> p.send_signal(signal.SIGUSR2)
+
+    >>> wait_until('new file', lambda : os.path.exists('l'))
+    >>> s = ClientStorage(port)
+    >>> s.close()
+    >>> wait_until('See logging', lambda : ('Log files ' in open('l').read()))
+    >>> open('o').read() == oldlog # No new data in old log
+    True
+
+    # Cleanup:
+
+    >>> p.kill()
+    >>> _ = p.wait()
+    """
+
+if sys.platform.startswith('win'):
+    del runzeo_logrotate_on_sigusr2
+
 if sys.version_info >= (2, 6):
     import multiprocessing
 



More information about the Zodb-checkins mailing list