[Zodb-checkins] CVS: Zope/lib/python/zdaemon - Daemon.py:1.14.6.2 __init__.py:1.4.26.1 zdaemon.py:1.3.2.2 Heartbeat.py:NONE SignalHandler.py:NONE ZDaemonLogging.py:NONE

Andreas Jung andreas@andreas-jung.com
Sat, 16 Nov 2002 11:40:47 -0500


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

Modified Files:
      Tag: ajung-restructuredtext-integration-branch
	Daemon.py __init__.py zdaemon.py 
Removed Files:
      Tag: ajung-restructuredtext-integration-branch
	Heartbeat.py SignalHandler.py ZDaemonLogging.py 
Log Message:
merge from trunk

=== Zope/lib/python/zdaemon/Daemon.py 1.14.6.1 => 1.14.6.2 ===
--- Zope/lib/python/zdaemon/Daemon.py:1.14.6.1	Sat Nov  9 03:43:01 2002
+++ Zope/lib/python/zdaemon/Daemon.py	Sat Nov 16 11:40:46 2002
@@ -13,7 +13,6 @@
 ##############################################################################
 
 import os, sys, time, signal
-from ZDaemonLogging import pstamp
 import zLOG
 
 pyth = sys.executable
@@ -146,3 +145,6 @@
             if startswith('SIG') and not startswith('SIG_'):
                 _signals[v] = k
     return _signals.get(n, 'unknown')
+
+def pstamp(message, sev):
+    zLOG.LOG("zdaemon", sev, message)


=== Zope/lib/python/zdaemon/__init__.py 1.4 => 1.4.26.1 ===
--- Zope/lib/python/zdaemon/__init__.py:1.4	Wed Aug 14 18:12:52 2002
+++ Zope/lib/python/zdaemon/__init__.py	Sat Nov 16 11:40:46 2002
@@ -12,46 +12,6 @@
 # FOR A PARTICULAR PURPOSE
 #
 ##############################################################################
-"""
-
-zinit, slightly smarter server manager and ZServer startup script.
-
-  zinit will:
-
-    - Fork a parent and a child
-
-    - restart the child if it dies
-
-    - write a pid file so you can kill (the parent)
-
-    - reports the childs pid to stdout so you can kill that too
-
-TODO
-
-  - Have the parent reap the children when it dies
-
-  - etc.
-
-"""
+"""zdaemon -- a package to manage a daemon application."""
 
 from Daemon import run
-
-# XXX Is the following a useful feature?
-
-def main():
-    import sys
-    argv=sys.argv[1:]
-    if argv and argv[0][:2]=='-p':
-        pidf=argv[0][2:]
-        del argv[0]
-    else:
-        pidf=''
-
-    if not argv:
-        print __doc__ % vars()
-        print
-        print 'Error: no script given'
-
-    run(argv, pidf)
-
-if __name__ == '__main__': main()


=== Zope/lib/python/zdaemon/zdaemon.py 1.3.2.1 => 1.3.2.2 === (842/942 lines abridged)
--- Zope/lib/python/zdaemon/zdaemon.py:1.3.2.1	Sat Nov  9 03:43:01 2002
+++ Zope/lib/python/zdaemon/zdaemon.py	Sat Nov 16 11:40:46 2002
@@ -4,23 +4,42 @@
 zdaemon -- run an application as a daemon.
 
 Usage: python zdaemon.py [zdaemon-options] program [program-arguments]
+Or:    python zdaemon.py -c [command]
 
 Options:
   -b SECONDS -- set backoff limit to SECONDS (default 10; see below)
+  -c -- client mode, to sends a command to the daemon manager; see below
   -d -- run as a proper daemon; fork a background process, close files etc.
   -f -- run forever (by default, exit when the backoff limit is exceeded)
   -h -- print usage message and exit
+  -s SOCKET -- Unix socket name for client communication (default "zdsock")
+  -x LIST -- list of fatal exit codes (default "0,2"; use "" to disable)
+  -z DIRECTORY -- directory to chdir into when using -d; default "/"
   program [program-arguments] -- an arbitrary application to run
 
+Client mode options:
+  -s SOCKET -- socket name (a Unix pathname) for client communication
+  [command] -- the command to send to the daemon manager (default "status")
+
+Client commands are:
+  help -- return command help
+  status -- report application status (this is the default command)
+  kill [signal] -- send a signal to the application
+                   (default signal is SIGTERM)
+  start -- start the application if not already running
+  stop -- stop the application if running; daemon manager keeps running
+  restart -- stop followed by start
+  exit -- stop the application and exit
+
 This daemon manager has two purposes: it restarts the application when
 it dies, and (when requested to do so with the -d option) it runs the
 application in the background, detached from the foreground tty
 session that started it (if any).
 
-Important: if at any point the application exits with exit status 2,
-it is not restarted.  Any other form of termination (either being
-killed by a signal or exiting with an exit status other than 2) causes
-it to be restarted.
+Important: if at any point the application exits with an exit status
+listed by the -x option, it is not restarted.  Any other form of
+termination (either being killed by a signal or exiting with an exit
+status not listed in the -x option) causes it to be restarted.
 
 Backoff limit: when the application exits (nearly) immediately after a
 restart, the daemon manager starts slowing down by delaying between
@@ -33,92 +52,154 @@

[-=- -=- -=- 842 lines omitted -=- -=- -=-]

+        if hasattr(os, "WCOREDUMP"):
+            iscore = os.WCOREDUMP(sts)
+        else:
+            iscore = sts & 0x80
+        if iscore:
+            msg += " (core dumped)"
+        return -1, msg
+    else:
+        msg = "unknown termination cause 0x%04x" % sts
+        return -1, msg
+
+_signames = None
+
+def signame(sig):
+    """Return a symbolic name for a signal.
+
+    Return "signal NNN" if there is no corresponding SIG name in the
+    signal module.
+    """
+
+    if _signames is None:
+        _init_signames()
+    return _signames.get(sig) or "signal %d" % sig
+
+def _init_signames():
+    global _signames
+    d = {}
+    for k, v in signal.__dict__.items():
+        k_startswith = getattr(k, "startswith", None)
+        if k_startswith is None:
+            continue
+        if k_startswith("SIG") and not k_startswith("SIG_"):
+            d[v] = k
+    _signames = d
+
+def get_path():
+    """Return a list corresponding to $PATH, or a default."""
+    path = ["/bin", "/usr/bin", "/usr/local/bin"]
+    if os.environ.has_key("PATH"):
+        p = os.environ["PATH"]
+        if p:
+            path = p.split(os.pathsep)
+    return path
 
-    def log(self, msg, severity=zLOG.INFO):
-        zLOG.LOG(self.getsubsystem(), severity, msg)
+# Main program
 
 def main(args=None):
     d = Daemonizer()

=== Removed File Zope/lib/python/zdaemon/Heartbeat.py ===

=== Removed File Zope/lib/python/zdaemon/SignalHandler.py ===

=== Removed File Zope/lib/python/zdaemon/ZDaemonLogging.py ===