[Zope-Checkins] CVS: Zope/inst/skel/inst/skel/bin - ntservice.py:1.1.2.1
Chris McDonough
chrism@zope.com
Sun, 6 Oct 2002 17:42:53 -0400
Update of /cvs-repository/Zope/inst/skel/inst/skel/bin
In directory cvs.zope.org:/tmp/cvs-serv16746/inst/skel/inst/skel/bin
Added Files:
Tag: chrism-install-branch
ntservice.py
Log Message:
Added support for creating NT services from instance homes.
This works by building an instance home normally and then from the
instance home running "bin\ntservice.py install". The service is named
after the instance, and each instance can have its own service installed.
In the process, moved "zctl.py" into a "bin" directory, and moved "zope.conf"
into an "etc" directory inside an instance home.
=== Added File Zope/inst/skel/inst/skel/bin/ntservice.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""
Installs, removes, stops, and starts a Windows NT service related to the
Zope instance home in which it's installed.
"""
import zctl
from Controller.NTService import NTService
import win32serviceutil
import win32api
import os, sys
# assumes zctl is in bin dir of instance home
dn = os.path.dirname
instance = os.path.abspath(dn(dn(zctl.__file__)))
servicename = os.path.splitdrive(instance)[1]
servicename = servicename.replace("\\", '_')
servicename = servicename.replace(" ", "_")
if servicename.startswith('_'):
servicename = servicename[1:]
servicename = 'Zope_%s' % servicename
class InstanceService(NTService):
_svc_name_ = servicename
_svc_display_name_ = 'Zope instance at %s' % instance
def get_start_command(self):
os.chdir(instance) # hack, but required for successful service start
return win32serviceutil.GetServiceCustomOption(self,'start')
def get_stop_command(self):
os.chdir(instance) # hack, but required for successful service stop
return win32serviceutil.GetServiceCustomOption(self,'stop')
def usage():
print __doc__
def set_start_command(value):
"sets the ZServer start command if the start command is not already set"
current=win32serviceutil.GetServiceCustomOption(InstanceService,
'start', None)
if current is None:
win32serviceutil.SetServiceCustomOption(InstanceService,'start',value)
def set_stop_command(value):
"sets the stop command if the stop command is not already set"
current=win32serviceutil.GetServiceCustomOption(InstanceService,
'stop', None)
if current is None:
win32serviceutil.SetServiceCustomOption(InstanceService,'stop',value)
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(InstanceService)
if 'install' in sys.argv:
python = win32api.GetShortPathName(sys.executable)
zctl = zctl.__file__
if zctl[-3:] in ('pyc', 'pyo'):
zctl = zctl[:-1]
cmd = win32api.GetShortPathName(zctl)
start_command="%s %s start" % (python, cmd)
stop_command ="%s %s stop" % (python, cmd)
set_start_command(start_command)
set_stop_command(stop_command)
print "Setting Zope instance start command to:", start_command
print "Setting Zope instance stop command to:", stop_command