[Zodb-checkins] SVN: ZODB/branches/3.9/src/ Bug Fixed

Jim Fulton jim at zope.com
Tue Sep 28 16:19:23 EDT 2010


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

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

-=-
Modified: ZODB/branches/3.9/src/CHANGES.txt
===================================================================
--- ZODB/branches/3.9/src/CHANGES.txt	2010-09-28 20:07:58 UTC (rev 117031)
+++ ZODB/branches/3.9/src/CHANGES.txt	2010-09-28 20:19:23 UTC (rev 117032)
@@ -15,6 +15,9 @@
   Python 2.7 wasn't officially supported, but we were releasing
   binaries for it, so ...
 
+- Logrotation/repoening via a SIGUSR2 signal wasn't implemented.
+  (https://bugs.launchpad.net/zodb/+bug/143600)
+
 3.9.6 (2010-09-21)
 ==================
 

Modified: ZODB/branches/3.9/src/ZEO/runzeo.py
===================================================================
--- ZODB/branches/3.9/src/ZEO/runzeo.py	2010-09-28 20:07:58 UTC (rev 117031)
+++ ZODB/branches/3.9/src/ZEO/runzeo.py	2010-09-28 20:19:23 UTC (rev 117032)
@@ -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/branches/3.9/src/ZEO/tests/testZEO.py
===================================================================
--- ZODB/branches/3.9/src/ZEO/tests/testZEO.py	2010-09-28 20:07:58 UTC (rev 117031)
+++ ZODB/branches/3.9/src/ZEO/tests/testZEO.py	2010-09-28 20:19:23 UTC (rev 117032)
@@ -1299,6 +1299,67 @@
 
     """
 
+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)
+    >>> forker.wait_until('started',
+    ...   lambda : os.path.exists('l') and ('listening on' in open('l').read())
+    ...   )
+
+    >>> oldlog = open('l').read()
+    >>> os.rename('l', 'o')
+    >>> os.kill(p.pid, signal.SIGUSR2)
+
+    >>> forker.wait_until('new file', lambda : os.path.exists('l'))
+    >>> s = ClientStorage(('', port))
+    >>> s.close()
+    >>> forker.wait_until('See logging',
+    ...                   lambda : ('Log files ' in open('l').read()))
+    >>> open('o').read() == oldlog # No new data in old log
+    True
+
+    # Cleanup:
+
+    >>> os.kill(p.pid, signal.SIGKILL)
+    >>> _ = p.wait()
+    """
+
+if sys.platform.startswith('win'):
+    del runzeo_logrotate_on_sigusr2
+
 def quick_close_doesnt_kill_server():
     r"""
 



More information about the Zodb-checkins mailing list