Commit 252f9eda authored by Brian Lloyd's avatar Brian Lloyd

Fix for refactored signal handler support.

parent 368f47ef
......@@ -254,74 +254,6 @@ here=os.path.join(os.getcwd(), os.path.split(program)[0])
Zpid=''
# Install signal handlers.
# SIGTERM - cleanly shuts down.
# SIGHUP - cleanly restarts.
# SIGUSR2 - open and close all log files (for log rotation)
if os.name == 'posix': # signal.signal() not reliable on Windows
import signal
def closeall():
zLOG.LOG('Z2', zLOG.INFO, "Closing all open network connections")
for socket in asyncore.socket_map.values():
try:
socket.close()
except:
pass
zLOG.LOG('Z2', zLOG.INFO, "Closing all open ZODB databases")
import Globals
for db in Globals.opened:
try:
db.close()
finally:
pass
def sighandler(signum, frame):
signame = zdaemon.Daemon.get_signal_name(signum)
zLOG.LOG('Z2', zLOG.INFO , "Caught signal %s" % signame)
if signum in [signal.SIGTERM, signal.SIGINT]:
closeall()
zLOG.LOG('Z2', zLOG.INFO , "Shutting down")
sys.exit(0)
if signum == signal.SIGHUP:
closeall()
zLOG.LOG('Z2', zLOG.INFO , "Restarting")
sys.exit(1)
if signum == signal.SIGUSR2:
zLOG.LOG('Z2', zLOG.INFO , "Reopening log files")
if hasattr(sys, '__lg') and hasattr(sys.__lg, 'reopen'):
sys.__lg.reopen()
zLOG.LOG('Z2', zLOG.BLATHER, "Reopened access log")
if (hasattr(sys, '__detailedlog') and
hasattr(sys.__detailedlog, 'reopen')):
zLOG.LOG('Z2', zLOG.BLATHER,"Reopened detailed request log")
sys.__detailedlog.reopen()
if hasattr(zLOG, '_set_stupid_dest'):
zLOG._set_stupid_dest(None)
else:
zLOG._stupid_dest = None
ZLogger.stupidFileLogger._stupid_dest = None
zLOG.LOG('Z2', zLOG.BLATHER, "Reopened event log")
zLOG.LOG('Z2', zLOG.INFO, "Log files reopened successfully")
INTERESTING_SIGNALS = {
signal.SIGTERM: sighandler,
signal.SIGHUP: sighandler,
signal.SIGUSR2: sighandler,
signal.SIGINT: sighandler,
}
def installsighandlers():
# normal kill, restart, and open&close logs respectively
for signum, sighandler in INTERESTING_SIGNALS.items():
signal.signal(signum, sighandler)
signame = zdaemon.Daemon.get_signal_name(signum)
zLOG.LOG('Z2',zLOG.BLATHER,"Installed sighandler for %s" % signame)
########################################################################
# Configuration section
......@@ -568,6 +500,9 @@ if LOCALE_ID is not None:
set_locale(LOCALE_ID)
# Import SignalHandler to install the default signal handlers.
from SignalHandler import SignalHandler
# from this point forward we can use the zope logger
# Import ZServer before we open the database or get at interesting
......@@ -581,7 +516,7 @@ if Zpid and not READ_ONLY:
sys.ZMANAGED=1
zdaemon.run(sys.argv, os.path.join(CLIENT_HOME, Zpid),
INTERESTING_SIGNALS.keys())
SignalHandler.getRegisteredSignals())
os.chdir(CLIENT_HOME)
......@@ -867,7 +802,7 @@ try:
except:
raise
# Check umask sanity and install signal handlers if we're on posix.
# Check umask sanity if we're on posix.
if os.name == 'posix':
# umask is silly, blame POSIX. We have to set it to get its value.
current_umask = os.umask(0)
......@@ -877,8 +812,8 @@ try:
zLOG.LOG("z2", zLOG.INFO, 'Your umask of ' + current_umask + \
' may be too permissive; for the security of your ' + \
'Zope data, it is recommended you use 077')
# we've deferred til now to actuall install signal handlers
installsighandlers()
except:
# Log startup exception and tell zdaemon not to restart us.
......
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