[Zope-Checkins] CVS: Packages/ZEO - component.xml:1.4.6.1 mkzeoinst.py:1.18.8.4 runzeo.py:1.15.6.5

2005-04-12 Thread Sidnei da Silva
Update of /cvs-repository/Packages/ZEO
In directory cvs.zope.org:/tmp/cvs-serv13625

Modified Files:
  Tag: Zope-2_7-branch
component.xml mkzeoinst.py runzeo.py 
Log Message:

* Borrow Zope's 'Signal' mechanism for Windows, if available, to
  implement clean shutdown and log rotation handlers for Windows.
* Back to creating a .PID for ZEO, so external programs that wish to set
  the 'signal' can get the PID and therefore derive the signal name.
  Currently only necessary on Windows but created on all platforms which
  implement os.getpid(), as long as the 'pid-filename' option is set,
  or the 'INSTANCE_HOME' environment variable can be found.


=== Packages/ZEO/component.xml 1.4 = 1.4.6.1 ===
--- Packages/ZEO/component.xml:1.4  Fri May 30 15:20:57 2003
+++ Packages/ZEO/component.xml  Tue Apr 12 22:54:54 2005
@@ -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


=== Packages/ZEO/mkzeoinst.py 1.18.8.3 = 1.18.8.4 ===
--- Packages/ZEO/mkzeoinst.py:1.18.8.3  Wed Feb 18 17:10:14 2004
+++ Packages/ZEO/mkzeoinst.py   Tue Apr 12 22:54:54 2005
@@ -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


=== Packages/ZEO/runzeo.py 1.15.6.4 = 1.15.6.5 ===
--- Packages/ZEO/runzeo.py:1.15.6.4 Wed Jan 14 14:07:00 2004
+++ Packages/ZEO/runzeo.py  Tue Apr 12 22:54:54 2005
@@ -48,6 +48,11 @@
 obj = ZConfig.datatypes.SocketAddress(arg)
 return obj.family, obj.address
 
+def windows_shutdown_handler():
+# Called by the signal mechanism on Windows to perform shutdown.
+import asyncore
+asyncore.close_all()
+
 class ZEOOptionsMixin:
 
 storages = None
@@ -95,6 +100,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):
 
@@ -117,6 +124,7 @@
 self.setup_default_logging()
 self.check_socket()
 self.clear_socket()
+self.make_pidfile()
 try:
 self.open_storages()
 self.setup_signals()
@@ -125,6 +133,7 @@
 finally:
 self.close_storages()
 self.clear_socket()
+self.remove_pidfile()
 
 def setup_default_logging(self):
 if self.options.config_logger is not None:
@@ -175,6 +184,8 @@
 method is called without additional arguments.
 
 if os.name != posix:
+if os.name == nt:
+self.setup_win32_signals()
 return
 if hasattr(signal, 'SIGXFSZ'):
 signal.signal(signal.SIGXFSZ, signal.SIG_IGN) # Special case
@@ -186,6 +197,27 @@
 method()
 signal.signal(sig, wrapper)
 
+def setup_win32_signals(self):
+# Borrow the Zope Signals package win32 support, if available.
+# Signals does a check/log for the availability of pywin32.
+try:
+import Signals.Signals
+except ImportError:
+debug(Signals package not found. 
+  Windows-specific signal handler 
+  will *not* be installed.)
+return
+SignalHandler = Signals.Signals.SignalHandler
+if SignalHandler is not None: # may be None if no pywin32.
+SignalHandler.registerHandler(signal.SIGTERM,
+  windows_shutdown_handler)
+SignalHandler.registerHandler(signal.SIGINT,
+  windows_shutdown_handler)
+# Can use the log rotate handler too.
+from Signals.Signals import logfileRotateHandler
+SIGUSR2 = 12 # not in signal module on Windows.
+SignalHandler.registerHandler(SIGUSR2, logfileRotateHandler)
+
 def create_server(self):
 from ZEO.StorageServer import StorageServer
 self.server = StorageServer(
@@ -232,6 +264,53 @@
 except: # Keep going
 exception(failed to close storage %r % name)
 
+def _get_pidfile(self):
+pidfile = self.options.pid_file
+# 'pidfile' is marked as not required.
+if not pidfile:
+# Try to find a reasonable location if the pidfile is not
+# set. If we are running in a Zope environment, we can
+# safely assume INSTANCE_HOME.
+instance_home = os.environ.get(INSTANCE_HOME)
+if not 

[Zope-Checkins] CVS: Zope/skel/bin - zopeservice.py.in:1.1.2.10

2005-04-12 Thread Sidnei da Silva
Update of /cvs-repository/Zope/skel/bin
In directory cvs.zope.org:/tmp/cvs-serv27740/skel/bin

Modified Files:
  Tag: Zope-2_7-branch
zopeservice.py.in 
Log Message:

Major service enhancements.  Service cleanly shuts down child, and if child
fails the tail of the process output (which generally contains a traceback)
is
written to the event log.

Minor tweaks to the Windows build 'clean' process and documentation tweaks.


=== Zope/skel/bin/zopeservice.py.in 1.1.2.9 = 1.1.2.10 ===
--- Zope/skel/bin/zopeservice.py.in:1.1.2.9 Thu Dec 16 13:08:39 2004
+++ Zope/skel/bin/zopeservice.py.in Tue Apr 12 23:41:34 2005
@@ -38,8 +38,9 @@
 
   install : Installs the service
 
-  update : Updates the service, use this when you change
-   the service class implementation 
+  update : Updates the service.  Use this if you change any
+   configuration settings and need the service to be
+   re-registered.
 
   remove : Removes the service
 
@@ -53,13 +54,9 @@
 
   debug : Runs the service in debug mode
 
-You can view the usage options by running ntservice.py without any
+You can view the usage options by running this module without any
 arguments.
 
-Note: you may have to register the Python service program first,
-
-  win32\PythonService.exe /register
-
   Starting Zope
 
 Start Zope by clicking the 'start' button in the services control
@@ -74,19 +71,17 @@
 
   Event logging
 
-Zope events are logged to the NT application event log. Use the
-event viewer to keep track of Zope events.
+Service related events (such as startup, shutdown, or errors executing
+the Zope process) are logged to the NT application event log. Use the
+event viewer to see these events.
 
-Note: to successfully run this script, the Zope software home needs to be on
-the PYTHONPATH.
-
+Zope Events are still written to the Zope event logs.
 
-import os.path
-from os.path import dirname as dn
-import sys
+
+import sys, os
 
 # these are replacements from mkzopeinstance
-PYTHONW = r'PYTHONW'
+PYTHON = r'PYTHON'
 SOFTWARE_HOME=r'SOFTWARE_HOME'
 INSTANCE_HOME = r'INSTANCE_HOME'
 ZOPE_HOME = r'ZOPE_HOME'
@@ -95,17 +90,35 @@
 CONFIG_FILE= os.path.join(INSTANCE_HOME, 'etc', 'zope.conf')
 PYTHONSERVICE_EXE=r'%s\bin\PythonService.exe' % ZOPE_HOME
 
-os.environ['PYTHONPATH'] = SOFTWARE_HOME
+# Setup the environment, so sub-processes see these variables
+parts = os.environ.get(PYTHONPATH, ).split(os.pathsep)
+if SOFTWARE_HOME not in parts:
+parts = filter(None, [SOFTWARE_HOME] + parts)
+os.environ[PYTHONPATH] = os.pathsep.join(parts)
+os.environ[INSTANCE_HOME] = INSTANCE_HOME
+
+# Ensure SOFTWARE_HOME is on our current sys.path so we can import the
+# nt_svcutils package.
+if SOFTWARE_HOME not in sys.path:
+sys.path.insert(0, SOFTWARE_HOME)
 
 from nt_svcutils.service import Service
 
 servicename = 'Zope_%s' % str(hash(INSTANCE_HOME.lower()))
 
 class InstanceService(Service):
-start_cmd = '%s %s -C %s' % (PYTHONW, ZOPE_RUN, CONFIG_FILE)
 _svc_name_ = servicename
 _svc_display_name_ = 'Zope instance at %s' % INSTANCE_HOME
-_exe_name_ = PYTHONSERVICE_EXE
+# _svc_description_ can also be set (but what to say isn't clear!)
+# If the exe we expect is not there, let the service framework search
+# for it.  This will be true for people running from source builds and
+# relying on pre-installed pythonservice.exe.
+# Note this is only used at install time, not runtime.
+if os.path.isfile(PYTHONSERVICE_EXE):
+_exe_name_ = PYTHONSERVICE_EXE
+
+process_runner = PYTHON
+process_args = '%s -C %s' % (ZOPE_RUN, CONFIG_FILE)
 
 if __name__ == '__main__':
 import win32serviceutil

___
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins