[Zope-Checkins] CVS: Zope - z2.py:1.71

Brian Lloyd brian@zope.com
Fri, 14 Jun 2002 11:25:41 -0400


Update of /cvs-repository/Zope
In directory cvs.zope.org:/tmp/cvs-serv31705

Modified Files:
	z2.py 
Log Message:
Fix for refactored signal handler support.


=== Zope/z2.py 1.70 => 1.71 ===
 
 
-#   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 @@
     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 @@
     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 @@
     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 @@
             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.