[Zodb-checkins] CVS: ZODB3/ZEO - start.py:1.45.6.1

Guido van Rossum guido@python.org
Wed, 16 Oct 2002 17:47:09 -0400


Update of /cvs-repository/ZODB3/ZEO
In directory cvs.zope.org:/tmp/cvs-serv598/branch-ZODB3/ZEO

Modified Files:
      Tag: ZODB3-3_1-branch
	start.py 
Log Message:
Merge from trunk: changes in signal handling (map different signals to
actions, write pid file).


=== ZODB3/ZEO/start.py 1.45 => 1.45.6.1 ===
--- ZODB3/ZEO/start.py:1.45	Sun Sep 22 21:52:50 2002
+++ ZODB3/ZEO/start.py	Wed Oct 16 17:47:07 2002
@@ -11,10 +11,8 @@
 # FOR A PARTICULAR PURPOSE
 #
 ##############################################################################
-"""Start the server storage.
+"""Start the ZEO storage server."""
 
-$Id$
-"""
 from __future__ import nested_scopes
 
 import sys, os, getopt
@@ -83,30 +81,26 @@
     except ImportError:
         return
 
-    try:
-        xfsz = signal.SIFXFSZ
-    except AttributeError:
-        pass
-    else:
-        signal.signal(xfsz, signal.SIG_IGN)
-    signal.signal(signal.SIGTERM, lambda sig, frame: shutdown(storages))
-    signal.signal(signal.SIGINT, lambda sig, frame: shutdown(storages, 0))
-    try:
-        signal.signal(signal.SIGHUP, rotate_logs_handler)
-    except:
-        pass
+    if hasattr(signal, 'SIGXFSZ'):
+        signal.signal(signal.SIGXFSZ, signal.SIG_IGN)
+    if hasattr(signal, 'SIGTERM'):
+        signal.signal(signal.SIGTERM, lambda sig, frame: shutdown(storages))
+    if hasattr(signal, 'SIGHUP'):
+        signal.signal(signal.SIGHUP, lambda sig, frame: shutdown(storages, 0))
+    if hasattr(signal, 'SIGUSR2'):
+        signal.signal(signal.SIGUSR2, rotate_logs_handler)
 
 def main(argv):
     me = argv[0]
     sys.path.insert(0, directory(me, 2))
 
     global LOG, INFO, ERROR
-    from zLOG import LOG, INFO, ERROR, PANIC
+    from zLOG import LOG, INFO, WARNING, ERROR, PANIC
     from ZEO.util import Environment
     env = Environment(me)
 
     # XXX hack for profiling support
-    global unix, storages, zeo_pid, asyncore
+    global unix, storages, asyncore
 
     args = []
     last = ''
@@ -172,7 +166,7 @@
     port = None
     debug = 0
     host = ''
-    unix =None
+    unix = None
     Z = 1
     UID = 'nobody'
     prof = None
@@ -225,10 +219,19 @@
             pass
         else:
             import zdaemon
-            zdaemon.run(sys.argv, '')
+            zdaemon.run(sys.argv, env.zeo_pid)
 
     try:
 
+        if Z:
+            # Change current directory (for core dumps etc.)
+            try:
+                os.chdir(env.var)
+            except os.error:
+                LOG('ZEO/start.py', WARNING, "Couldn't chdir to %s" % env.var)
+            else:
+                LOG('ZEO/start.py', INFO, "Changed directory to %s" % env.var)
+
         import ZEO.StorageServer, asyncore
 
         storages = {}
@@ -260,12 +263,15 @@
 
         ZEO.StorageServer.StorageServer(unix, storages)
 
-        try:
-            ppid, pid = os.getppid(), os.getpid()
-        except:
-            pass # getpid not supported
-        else:
-            open(env.zeo_pid,'w').write("%s %s" % (ppid, pid))
+        if not Z:
+            try:
+                pid = os.getpid()
+            except:
+                pass # getpid not supported
+            else:
+                f = open(env.zeo_pid, 'w')
+                f.write("%s\n" % pid)
+                f.close()
 
     except:
         # Log startup exception and tell zdaemon not to restart us.
@@ -281,7 +287,11 @@
         sys.exit(0)
 
     try:
-        asyncore.loop()
+        try:
+            asyncore.loop()
+        finally:
+            if os.path.isfile(env.zeo_pid):
+                os.unlink(env.zeo_pid)
     except SystemExit:
         raise
     except:
@@ -310,9 +320,6 @@
 
 def rotate_logs_handler(signum, frame):
     rotate_logs()
-
-    import signal
-    signal.signal(signal.SIGHUP, rotate_logs_handler)
 
 def shutdown(storages, die=1):
     LOG("ZEO/start.py", INFO, "Received signal")