[Zodb-checkins] CVS: Packages/ZEO - start.py:1.17

Jim Fulton jim@digicool.com
Tue, 27 Mar 2001 18:37:34 -0500 (EST)


Update of /cvs-repository/Packages/ZEO
In directory korak:/tmp/cvs-serv12718

Modified Files:
	start.py 
Log Message:

      - It is no longer necessary to symbolically link cPickle or
        ZServer. ZServer is no longer necessary at all.

      - A Zope-style INSTANCE_HOME and var directory are no longer 
        needed.

      - If ZServer *is* available, the medusa monitor server can be
        used in the storage server.

      - An option, -d, was added to facilitate generation of a
        detailed debug log while running in the background.



--- Updated File start.py in package Packages/ZEO --
--- start.py	2001/01/11 21:16:47	1.16
+++ start.py	2001/03/27 23:37:33	1.17
@@ -130,17 +130,25 @@
         args.append(a)
         last=a
 
-    INSTANCE_HOME=os.environ.get('INSTANCE_HOME', directory(me, 4))
+    if os.environ.has_key('INSTANCE_HOME'):
+        INSTANCE_HOME=os.environ['INSTANCE_HOME']
+    elif os.path.isdir(os.path.join(directory(me, 4),'var')):
+        INSTANCE_HOME=directory(me, 4)
+    else:
+        INSTANCE_HOME=os.getcwd()
+
+    if os.path.isdir(os.path.join(INSTANCE_HOME, 'var')):
+        var=os.path.join(INSTANCE_HOME, 'var')
+    else:
+        var=INSTANCE_HOME
 
     zeo_pid=os.environ.get('ZEO_SERVER_PID',
-                           os.path.join(INSTANCE_HOME, 'var', 'ZEO_SERVER.pid')
+                           os.path.join(var, 'ZEO_SERVER.pid')
                            )
 
-    opts, args = getopt.getopt(args, 'p:Dh:U:sS:u:')
+    opts, args = getopt.getopt(args, 'p:Ddh:U:sS:u:')
 
-    
-    
-    fs=os.path.join(INSTANCE_HOME, 'var', 'Data.fs')
+    fs=os.path.join(var, 'Data.fs')
 
     usage="""%s [options] [filename]
 
@@ -148,6 +156,9 @@
 
        -D -- Run in debug mode
 
+       -d -- Generate detailed debug logging without running
+             in the foreground.
+
        -U -- Unix-domain socket file to listen on
     
        -u username or uid number
@@ -182,7 +193,7 @@
     """ % (me, fs)
 
     port=None
-    debug=0
+    debug=detailed=0
     host=''
     unix=None
     Z=1
@@ -193,12 +204,10 @@
         elif o=='-U': unix=v
         elif o=='-u': UID=v
         elif o=='-D': debug=1
+        elif o=='-d': detailed=1
         elif o=='-s': Z=0
 
-    try:
-        from ZServer.medusa import asyncore
-        sys.modules['asyncore']=asyncore
-    except: pass
+    import fap # fixup asyncore/cPickle dependencies
 
     if port is None and unix is None:
         print usage
@@ -212,9 +221,10 @@
             sys.exit(1)
         fs=args[0]
 
-    __builtins__.__debug__=debug
     if debug: os.environ['Z_DEBUG_MODE']='1'
 
+    if detailed: os.environ['STUPID_LOG_SEVERITY']='-99999'
+
     from zLOG import LOG, INFO, ERROR
 
     # Try to set uid to "-u" -provided uid.
@@ -255,52 +265,67 @@
             import zdaemon
             zdaemon.run(sys.argv, '')
 
-    import ZEO.StorageServer, asyncore
+    try:
 
-    storages={}
-    for o, v in opts:
-        if o=='-S':
-            n, m = string.split(v,'=')
-            if string.find(m,':'):
-                # we got an attribute name
-                m, a = string.split(m,':')
-            else:
-                # attribute name must be same as storage name
-                a=n
-            storages[n]=get_storage(m,a)
-
-    if not storages:
-        import ZODB.FileStorage
-        storages['1']=ZODB.FileStorage.FileStorage(fs)
+        import ZEO.StorageServer, asyncore
 
-    # Try to set up a signal handler
-    try:
-        import signal
+        storages={}
+        for o, v in opts:
+            if o=='-S':
+                n, m = string.split(v,'=')
+                if string.find(m,':'):
+                    # we got an attribute name
+                    m, a = string.split(m,':')
+                else:
+                    # attribute name must be same as storage name
+                    a=n
+                storages[n]=get_storage(m,a)
+
+        if not storages:
+            import ZODB.FileStorage
+            storages['1']=ZODB.FileStorage.FileStorage(fs)
 
-        signal.signal(signal.SIGTERM,
-                      lambda sig, frame, s=storages: shutdown(s)
-                      )
-        signal.signal(signal.SIGINT,
-                      lambda sig, frame, s=storages: shutdown(s, 0)
-                      )
-        signal.signal(signal.SIGHUP, rotate_logs_handler)
+        # Try to set up a signal handler
+        try:
+            import signal
 
-    finally: pass
+            signal.signal(signal.SIGTERM,
+                          lambda sig, frame, s=storages: shutdown(s)
+                          )
+            signal.signal(signal.SIGINT,
+                          lambda sig, frame, s=storages: shutdown(s, 0)
+                          )
+            signal.signal(signal.SIGHUP, rotate_logs_handler)
 
-    items=storages.items()
-    items.sort()
-    for kv in items:
-        LOG('ZEO Server', INFO, 'Serving %s:\t%s' % kv)
+        finally: pass
 
-    if not unix: unix=host, port
+        items=storages.items()
+        items.sort()
+        for kv in items:
+            LOG('ZEO Server', INFO, 'Serving %s:\t%s' % kv)
 
-    ZEO.StorageServer.StorageServer(unix, storages)
+        if not unix: unix=host, port
 
+        ZEO.StorageServer.StorageServer(unix, storages)
 
-    open(zeo_pid,'w').write("%s %s" % (os.getppid(), os.getpid()))
-    
-    asyncore.loop()
 
+        open(zeo_pid,'w').write("%s %s" % (os.getppid(), os.getpid()))
+
+        asyncore.loop()
+    except:
+        # Log startup exception and tell zdaemon not to restart us.
+        info=sys.exc_info()
+        try:
+            import zLOG
+            zLOG.LOG("z2", zLOG.PANIC, "Startup exception",
+                     error=info)
+        except:
+            info2=sys.exc_info()
+            import traceback
+            traceback.print_exception(*info)
+            traceback.print_exception(*info2)
+            
+        sys.exit(0)
 
 def rotate_logs():
     import zLOG