[Zope-Checkins] SVN: Zope/trunk/ - The ZEO server now records its PID to a file like the ZEO

Sidnei da Silva sidnei at awkly.org
Thu Mar 17 07:14:32 EST 2005


Log message for revision 29523:
  
        - The ZEO server now records its PID to a file like the ZEO
          client. Defaults to /var/ZEO.pid, and its
          configurable in /etc/zeo.conf.
  

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/ZEO/component.xml
  U   Zope/trunk/lib/python/ZEO/mkzeoinst.py
  U   Zope/trunk/lib/python/ZEO/runzeo.py

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2005-03-17 12:12:01 UTC (rev 29522)
+++ Zope/trunk/doc/CHANGES.txt	2005-03-17 12:14:32 UTC (rev 29523)
@@ -28,6 +28,10 @@
 
     Features added
 
+      - The ZEO server now records its PID to a file like the ZEO
+        client. Defaults to $INSTANCE_HOME/var/ZEO.pid, and its
+        configurable in $INSTANCE_HOME/etc/zeo.conf.
+
       - PluginIndexes: the ZCatalog's "Indexes" tab now show the number of
         distinct values indexed by each index instead of a mixture of indexed
         objects versus number of distinct values. Indexes derived from UnIndex 

Modified: Zope/trunk/lib/python/ZEO/component.xml
===================================================================
--- Zope/trunk/lib/python/ZEO/component.xml	2005-03-17 12:12:01 UTC (rev 29522)
+++ Zope/trunk/lib/python/ZEO/component.xml	2005-03-17 12:14:32 UTC (rev 29523)
@@ -93,6 +93,15 @@
       </description>
     </key>
 
+    <key name="pid-filename" datatype="existing-dirpath"
+         required="no">
+      <description>
+        The full path to the file in which to write the ZEO server's Process ID
+        at startup. If omitted, $INSTANCE/var/ZEO.pid is used.
+      </description>
+      <metadefault>$INSTANCE/var/ZEO.pid (or $clienthome/ZEO.pid)</metadefault>
+    </key>
+
   </sectiontype>
 
 </component>

Modified: Zope/trunk/lib/python/ZEO/mkzeoinst.py
===================================================================
--- Zope/trunk/lib/python/ZEO/mkzeoinst.py	2005-03-17 12:12:01 UTC (rev 29522)
+++ Zope/trunk/lib/python/ZEO/mkzeoinst.py	2005-03-17 12:14:32 UTC (rev 29523)
@@ -47,6 +47,7 @@
   address %(port)d
   read-only false
   invalidation-queue-size 100
+  # pid-filename $INSTANCE/var/ZEO.pid
   # monitor-address PORT
   # transaction-timeout SECONDS
 </zeo>

Modified: Zope/trunk/lib/python/ZEO/runzeo.py
===================================================================
--- Zope/trunk/lib/python/ZEO/runzeo.py	2005-03-17 12:12:01 UTC (rev 29522)
+++ Zope/trunk/lib/python/ZEO/runzeo.py	2005-03-17 12:14:32 UTC (rev 29523)
@@ -104,6 +104,8 @@
                  None, 'auth-database=')
         self.add('auth_realm', 'zeo.authentication_realm',
                  None, 'auth-realm=')
+        self.add('pid_file', 'zeo.pid_filename',
+                 None, 'pid-file=')
 
 class ZEOOptions(ZDOptions, ZEOOptionsMixin):
 
@@ -126,6 +128,7 @@
         self.setup_default_logging()
         self.check_socket()
         self.clear_socket()
+        self.make_pidfile()
         try:
             self.open_storages()
             self.setup_signals()
@@ -134,6 +137,7 @@
         finally:
             self.close_storages()
             self.clear_socket()
+            self.remove_pidfile()
 
     def setup_default_logging(self):
         if self.options.config_logger is not None:
@@ -228,6 +232,37 @@
         #     Should we restart as with SIGHUP?
         log("received SIGUSR2, but it was not handled!", level=logging.WARNING)
 
+    def make_pidfile(self):
+        if not self.options.read_only:
+            pidfile = self.options.pid_file
+            # 'pidfile' is marked as not required.
+            if not pidfile:
+                pidfile = os.path.join(os.environ["INSTANCE_HOME"],
+                                       "var", "ZEO.pid")
+            try:
+                if os.path.exists(pidfile):
+                    os.unlink(pidfile)
+                pid = os.getpid()
+                f = open(pidfile,'w')
+                f.write(`pid`)
+                f.close()
+            except IOError:
+                error("PID file '%s' cannot be opened.")
+            except AttributeError:
+                pass  # getpid not supported. Unix/Win only
+
+    def remove_pidfile(self):
+        if not self.options.read_only:
+            pidfile = self.options.pid_file
+            if not pidfile:
+                pidfile = os.path.join(os.environ["INSTANCE_HOME"],
+                                       "var", "ZEO.pid")
+            try:
+                if os.path.exists(pidfile):
+                    os.unlink(pidfile)
+            except IOError:
+                error("PID file '%s' could not be removed.")
+
     def close_storages(self):
         for name, storage in self.storages.items():
             log("closing storage %r" % name)



More information about the Zope-Checkins mailing list