[Zope-Checkins] CVS: Zope/ZServer/PubCore - ZEvent.py:1.8

Chris McDonough chrism@zope.com
Tue, 11 Jun 2002 18:03:17 -0400


Update of /cvs-repository/Zope/ZServer/PubCore
In directory cvs.zope.org:/tmp/cvs-serv24893/PubCore

Modified Files:
	ZEvent.py 
Log Message:
These patches provide clean signal handling and logfile rotation to Zope.

All Zope process will respond to signals in the specified manner:

  SIGHUP -  close open database connections and sockets, then restart the
            process

  SIGTERM - close open database connections and sockets, then shut down.

  SIGINT  - same as SIGTERM

  SIGUSR2 - rotate all Zope log files (z2.log, event log, detailed log)

The common idiom for doing automated logfile rotation will become:

kill -USR2 `cat /path/to/var/z2.pid`

The common idiom for doing "prophylactic" restarts will become:

kill -HUP `cat /path/to/var/z2.pid`

When a process is interrupted via ctrl-C or via a TERM signal (INT, TERM),
all open database connections and sockets will be closed before
the process dies.  This will speed up restart time for sites that
use a FileStorage as its index will be written to the filesystem before
shutdown. 

Unspecified signals kill the process without doing cleanup.




=== Zope/ZServer/PubCore/ZEvent.py 1.7 => 1.8 ===
 
 from ZServer.medusa.thread.select_trigger import trigger
+from ZServer.medusa.asyncore import socket_map
+
+class simple_trigger(trigger):
+    def handle_close(self):
+        pass
+
+the_trigger=simple_trigger()
+
+def Wakeup(thunk=None):
+    try:
+        the_trigger.pull_trigger(thunk)
+    except OSError, why:
+        # this broken pipe as a result of perhaps a signal
+        # we want to handle this gracefully so we get rid of the old
+        # trigger and install a new one.
+        if why[0] == 32: 
+            del socket_map[the_trigger._fileno]
+            global the_trigger
+            the_trigger = simple_trigger() # adds itself back into socket_map
+            the_trigger.pull_trigger(thunk)
 
-Wakeup=trigger().pull_trigger