[Zodb-checkins] CVS: Zope/lib/python/zdaemon - Daemon.py:1.11.4.1

Chris McDonough chrism@zope.com
Mon, 2 Sep 2002 03:35:12 -0400


Update of /cvs-repository/Zope/lib/python/zdaemon
In directory cvs.zope.org:/tmp/cvs-serv17315/lib/python/zdaemon

Modified Files:
      Tag: chrism-install-branch
	Daemon.py 
Log Message:
Overhaul of installer branch.

z2.py is no longer necessary (nor used in the default config).  
In prior iterations of the installer branch, the "controller" process
(zctl) "front-ended" for z2.py, translating environment variables and
command-line options as necessary to pass in to z2.py.

In this iteration, a new file named "zope.py" is responsible for starting
the Zope process.  It reads configuration directives directly and has
the capability to obtain a configuration from a file or via XML-RPC.
z2.py still exists in the branch, but it's unused.

The zope.py file can be used to start Zope, but a nicer front-end
for it is "zctl", which is a heavily-modified offshoot of Tres'
"zopectl".  The zctl module is now generalized enough that it
*might* be able to run on Windows (I haven't tested it, though).

zctl is still a standalone process.  This is to allow for the fact that
Windows doesn't have os.fork (or zctl would have just imported zope.py
and forked).

In order to maintain cross-platform capability, the "logtail" option
of zctl was removed.  We should create a Python "tail" function
to get around this.

Niceties: zctl is able to tell if its Zope is already running (so you
cant inadvertently start it twice).  The Z2.pid file is cleaned up
when Zope exits, also.

A small bug in FindHomes.py was also fixed (dont add SOFTWARE_HOME to
sys.path if it's already in there).  Additionally, zdaemon was modified
so that if a child Zope process exits with error code 255, the daemon
process does not restart it (not strictly necessary, but nice to have).


=== Zope/lib/python/zdaemon/Daemon.py 1.11 => 1.11.4.1 ===
--- Zope/lib/python/zdaemon/Daemon.py:1.11	Wed Aug 14 18:12:52 2002
+++ Zope/lib/python/zdaemon/Daemon.py	Mon Sep  2 03:35:10 2002
@@ -22,6 +22,9 @@
 class DieNow(Exception):
     pass
 
+class DieNowWithError(Exception):
+    pass
+
 def run(argv, pidfile=''):
     if os.environ.has_key('ZDAEMON_MANAGED'):
         # We're being run by the child.
@@ -47,11 +50,17 @@
                 write_pidfile(pidfile)
                 p,s = wait(pid) # waitpid will block until child exit
                 if s:
-                    # continue and restart because our child died
-                    # with a nonzero exit code, meaning he bit it in
-                    # an unsavory way (likely a segfault or something)
-                    log_pid(p, s)
-                    continue
+                    # 255 is a reserved status code which means
+                    # that a startup could not be executed, so we allow
+                    # our child to die if this status code is encountered.
+                    # Otherwise, continue and restart because our child died
+                    # with another nonzero exit code, meaning he bit it in
+                    # an unsavory way.
+                    if os.WIFEXITED(s) and os.WEXITSTATUS(s) == 255:
+                        raise DieNowWithError
+                    else:
+                        log_pid(p, s)
+                        continue
                 else:
                     # no need to restart, our child wanted to die.
                     raise DieNow
@@ -66,6 +75,8 @@
 
         except DieNow:
             sys.exit()
+        except DieNowWithError:
+            sys.exit(1)
 
 def detach():
     # do the funky chicken dance to detach from the terminal