[Zodb-checkins] CVS: Zope/lib/python/zdaemon - Daemon.py:1.11.6.1 SignalPasser.py:NONE
   
    Chris McDonough
     
    chrism@zope.com
       
    Tue, 8 Oct 2002 17:18:21 -0400
    
    
  
Update of /cvs-repository/Zope/lib/python/zdaemon
In directory cvs.zope.org:/tmp/cvs-serv12320/lib/python/zdaemon
Modified Files:
      Tag: Zope-2_6-branch
	Daemon.py 
Removed Files:
      Tag: Zope-2_6-branch
	SignalPasser.py 
Log Message:
Dumb bug in zdaemon fixed in which it would try to kill process numbers 1, 2, 3, 10, 12, and 15
when it caught a signal related to any of these signal numbers. ;-)  Instead, it
actually tries now to kill its child process with the same signal.
Pidfile handling improved.
When Zope is started under zdaemon, it no longer writes its own pidfile.  Instead, it passes in the path to Z2.pid to zdaemon as its pidfile name.  The 'zProcessManager.pid' file is no longer ever written.
This caused a change to the -Z option of z2.py which should be mostly backwards-compatible (unless people were relying on zProcessManager.pid to be written).  Now the -Z option is a boolean.  -Z1 means use a daemon.  -Z0 means dont.  The default is -Z1.
Write pidfiles out with trailing newlines.
Minor reorganization of "SignalPasser" code (move it from its own module into zdaemon).
=== Zope/lib/python/zdaemon/Daemon.py 1.11 => 1.11.6.1 ===
--- Zope/lib/python/zdaemon/Daemon.py:1.11	Wed Aug 14 18:12:52 2002
+++ Zope/lib/python/zdaemon/Daemon.py	Tue Oct  8 17:18:21 2002
@@ -15,13 +15,25 @@
 import os, sys, time, signal
 from ZDaemonLogging import pstamp
 import zLOG
-from SignalPasser import SignalPasser
 
 pyth = sys.executable
 
 class DieNow(Exception):
     pass
 
+class SignalPasser:
+    """ A class used for passing signal that the daemon receives along to
+    its child """
+    def __init__(self, pid):
+        self.pid = pid
+
+    def __call__(self, signum, frame):
+        # send the signal to our child
+        os.kill(self.pid, signum)
+        # we want to die ourselves if we're signaled with SIGTERM or SIGINT
+        if signum in [signal.SIGTERM, signal.SIGINT]:
+            raise DieNow
+
 def run(argv, pidfile=''):
     if os.environ.has_key('ZDAEMON_MANAGED'):
         # We're being run by the child.
@@ -42,7 +54,7 @@
                 interesting = [1, 2, 3, 10, 12, 15]
                 # ie. HUP, INT, QUIT, USR1, USR2, TERM
                 for sig in interesting:
-                    signal.signal(sig, SignalPasser(sig))
+                    signal.signal(sig, SignalPasser(pid))
                 pstamp('Houston, we have forked: pid %s' % pid, zLOG.INFO)
                 write_pidfile(pidfile)
                 p,s = wait(pid) # waitpid will block until child exit
@@ -79,7 +91,7 @@
 def write_pidfile(pidfile):
     if pidfile:
         pf = open(pidfile, 'w+')
-        pf.write(("%s" % os.getpid()))
+        pf.write(("%s\n" % os.getpid()))
         pf.close()
 
 def wait(pid):
@@ -121,8 +133,7 @@
         signame = get_signal_name(signum)
         msg = "stopped by signal %s(%s)" % (signame,
                                             signum)
-    pstamp('Aiieee! Process %s %s' % (p, msg),
-           zLOG.ERROR)
+    pstamp('Aieeee!  Process %s %s' % (p, msg), zLOG.ERROR)
 
 _signals = None
 
=== Removed File Zope/lib/python/zdaemon/SignalPasser.py ===