Commit b0b24cea authored by Jim Fulton's avatar Jim Fulton

Bug fixed

- Logrotation/repoening via a SIGUSR2 signal wasn't implemented.
  (https://bugs.launchpad.net/zodb/+bug/143600)

Needs windows test.
parent ec7effb1
...@@ -41,6 +41,11 @@ Bugs fixed ...@@ -41,6 +41,11 @@ Bugs fixed
- Object ids created in a savepoint that is rolled back wren't being - Object ids created in a savepoint that is rolled back wren't being
reused. (https://bugs.launchpad.net/zodb/+bug/588389) 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) 3.10.0b6 (2010-09-08)
===================== =====================
......
...@@ -269,10 +269,30 @@ class ZEOServer: ...@@ -269,10 +269,30 @@ class ZEOServer:
sys.exit(1) sys.exit(1)
def handle_sigusr2(self): def handle_sigusr2(self):
# TODO: this used to reinitialize zLOG. How do I achieve # log rotation signal - do the same as Zope 2.7/2.8...
# the same effect with Python's logging package? if self.options.config_logger is None or os.name not in ("posix", "nt"):
# Should we restart as with SIGHUP? log("received SIGUSR2, but it was not handled!",
log("received SIGUSR2, but it was not handled!", level=logging.WARNING) 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): def close_storages(self):
for name, storage in self.storages.items(): for name, storage in self.storages.items():
......
...@@ -1476,6 +1476,66 @@ But, if we abort, we'll get up to date data and we'll see the changes. ...@@ -1476,6 +1476,66 @@ But, if we abort, we'll get up to date data and we'll see the changes.
""" """
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): if sys.version_info >= (2, 6):
import multiprocessing import multiprocessing
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment