""" A ZEO Windows NT service frontend. Usage: Installation The ZEO service should be installed by the Zope Windows installer. You can manually install, uninstall the service from the commandline. ntservice.py [options] install|update|remove|start [...] |stop|restart [...]|debug [...] Options for 'install' and 'update' commands only: --username domain\username : The Username the service is to run under --password password : The password for the username --startup [manual|auto|disabled] : How the service starts, default = manual Commands install : Installs the service update : Updates the service. Use this if you change any configuration settings and need the service to be re-registered. remove : Removes the service start : Starts the service, this can also be done from the services control panel stop : Stops the service, this can also be done from the services control panel restart : Restarts the service debug : Runs the service in debug mode You can view the usage options by running this module without any arguments. Starting ZEO Start ZEO by clicking the 'start' button in the services control panel. You can set ZEO to automatically start at boot time by choosing 'Auto' startup by clicking the 'statup' button. Stopping ZEO Stop ZEO by clicking the 'stop' button in the services control panel. Event logging 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. ZEO Events are still written to the ZEO event logs. """ import sys, os # these are replacements from mkzopeinstance PYTHON = r'%(PYTHON)s' INSTANCE_HOME = r'%(INSTANCE_HOME)s' ZODB3_HOME = r'%(zodb3_home)s' PYTHONPATH = r'%(PYTHONPATH)s' PID_FILENAME = r'%(PID_FILENAME)s' ZEO_RUN = r'%%s\\ZEO\\runzeo.py' %% ZODB3_HOME CONFIG_FILE= os.path.join(INSTANCE_HOME, 'etc', 'zeo.conf') import win32service PYTHONSERVICE_EXE=os.path.join(os.path.dirname(win32service.__file__), 'PythonServicea.exe') # Setup the environment, so sub-processes see these variables parts = os.environ.get("PYTHONPATH", "").split(os.pathsep) for part in PYTHONPATH.split(os.pathsep): if part not in parts: parts.append(part) os.environ["PYTHONPATH"] = os.pathsep.join(parts) sys.path[0:0] = parts from nt_svcutils.service import Service servicename = 'ZEO_%%s' %% str(hash(INSTANCE_HOME.lower())) class InstanceService(Service): _svc_name_ = servicename _svc_display_name_ = 'ZEO instance at %%s' %% INSTANCE_HOME # _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"' %% (ZEO_RUN, CONFIG_FILE) def __init__(self, args): self.setReg('command', self.process_runner + " " + self.process_args) self.setReg('pid_filename', PID_FILENAME) Service.__init__(self, args) def main(cls=InstanceService): serviceClassString = None if __name__ != '__main__': # HandleCommandLine can only resolve the full path to the # module to be imported if we are being executed directly. So # account for that and resolve the serviceClassString # ourselves otherwise, by using code similar to the one used # in win32serviceutil.GetServiceClassString import win32api fname = win32api.GetFullPathName(__file__) modName = os.path.splitext(fname)[0] serviceClassString = modName + "." + cls.__name__ import win32serviceutil win32serviceutil.HandleCommandLine(cls, serviceClassString) if __name__ == '__main__': main()