Commit 1dc25fc1 authored by 's avatar

Many fixes to ZService.py to get sys.path setup correctly at startup

time and fixes to allow multiple ZService instances to be installed
based on an INSTANCE_NAME provided by the WISE installer.
parent b75d6204
......@@ -183,22 +183,24 @@ TODO:
This script does for NT the same sort of thing zdaemon.py does for UNIX.
Requires Python win32api extensions.
"""
import sys
sys.path.append('./lib/win32')
import win32api, win32serviceutil, win32service, win32event, win32process
try: import servicemanager
except: pass
import time, imp, sys
import sys, os, string, time, imp
# Some fancy path footwork is required here because we
# may be run from python.exe or lib/win32/PythonService.exe
home=os.path.split(os.path.split(sys.executable)[0])[0]
if sys.executable[-10:]!='python.exe':
home=os.path.split(home)[0]
home=os.path.split(home)[0]
sys.path.append(os.path.join(home, 'ZServer'))
sys.path.append(os.path.join(home, 'bin', 'lib', 'win32'))
sys.path.append(os.path.join(home, 'bin', 'lib', 'win32', 'lib'))
try:
import App.version_txt
ZOPE_VERSION=App.version_txt.version_txt()
except:
ZOPE_VERSION='1.10.x'
# pythoncom and pywintypes are special, and require these hacks when
# we dont have a standard Python installation around.
import win32api
def magic_import(modulename, filename):
# by Mark Hammond
try:
......@@ -219,9 +221,24 @@ def magic_import(modulename, filename):
magic_import('pywintypes','pywintypes15.dll')
import win32serviceutil, win32service, win32event, win32process
try: import servicemanager
except: pass
class ZServerService(win32serviceutil.ServiceFramework):
_svc_name_ = "Zope%s" % ZOPE_VERSION
_svc_display_name_ = "Zope (%s)" % ZOPE_VERSION
# Some trickery to determine the service name. The WISE
# installer will write an svcname.txt to the ZServer dir
# that we can use to figure out our service name.
path=os.path.join(home, 'ZServer', 'svcname.txt')
file=open(path, 'r')
_svc_name_=string.strip(file.readline())
file.close()
_svc_display_name_ = "Zope (%s)" % _svc_name_
restart_min_time=5 # if ZServer restarts before this many
# seconds then we have a problem, and
......@@ -252,6 +269,7 @@ class ZServerService(win32serviceutil.ServiceFramework):
win32event.SetEvent(self.hWaitStop)
def start_zserver(self):
sc=self.get_start_command()
result=win32process.CreateProcess(None, self.get_start_command(),
None, None, 0, 0, None, None, win32process.STARTUPINFO())
self.hZServer=result[0]
......@@ -285,10 +303,7 @@ def set_start_command(value):
if __name__=='__main__':
win32serviceutil.HandleCommandLine(ZServerService)
if sys.argv[1]=='install':
if win32serviceutil.GetServiceCustomOption(ZServerService,'start') is None:
import string, os.path
home=string.split(sys.argv[0],'ZServer')[0]
command='"%s" "%s" -S' % (sys.executable, os.path.join(home,'z2.py'))
set_start_command(command)
print "Setting ZServer start command to:", command
if 'install' in sys.argv:
command='"%s" "%s" -S' % (sys.executable, os.path.join(home,'z2.py'))
set_start_command(command)
print "Setting ZServer start command to:", command
......@@ -183,22 +183,24 @@ TODO:
This script does for NT the same sort of thing zdaemon.py does for UNIX.
Requires Python win32api extensions.
"""
import sys
sys.path.append('./lib/win32')
import win32api, win32serviceutil, win32service, win32event, win32process
try: import servicemanager
except: pass
import time, imp, sys
import sys, os, string, time, imp
# Some fancy path footwork is required here because we
# may be run from python.exe or lib/win32/PythonService.exe
home=os.path.split(os.path.split(sys.executable)[0])[0]
if sys.executable[-10:]!='python.exe':
home=os.path.split(home)[0]
home=os.path.split(home)[0]
sys.path.append(os.path.join(home, 'ZServer'))
sys.path.append(os.path.join(home, 'bin', 'lib', 'win32'))
sys.path.append(os.path.join(home, 'bin', 'lib', 'win32', 'lib'))
try:
import App.version_txt
ZOPE_VERSION=App.version_txt.version_txt()
except:
ZOPE_VERSION='1.10.x'
# pythoncom and pywintypes are special, and require these hacks when
# we dont have a standard Python installation around.
import win32api
def magic_import(modulename, filename):
# by Mark Hammond
try:
......@@ -219,9 +221,24 @@ def magic_import(modulename, filename):
magic_import('pywintypes','pywintypes15.dll')
import win32serviceutil, win32service, win32event, win32process
try: import servicemanager
except: pass
class ZServerService(win32serviceutil.ServiceFramework):
_svc_name_ = "Zope%s" % ZOPE_VERSION
_svc_display_name_ = "Zope (%s)" % ZOPE_VERSION
# Some trickery to determine the service name. The WISE
# installer will write an svcname.txt to the ZServer dir
# that we can use to figure out our service name.
path=os.path.join(home, 'ZServer', 'svcname.txt')
file=open(path, 'r')
_svc_name_=string.strip(file.readline())
file.close()
_svc_display_name_ = "Zope (%s)" % _svc_name_
restart_min_time=5 # if ZServer restarts before this many
# seconds then we have a problem, and
......@@ -252,6 +269,7 @@ class ZServerService(win32serviceutil.ServiceFramework):
win32event.SetEvent(self.hWaitStop)
def start_zserver(self):
sc=self.get_start_command()
result=win32process.CreateProcess(None, self.get_start_command(),
None, None, 0, 0, None, None, win32process.STARTUPINFO())
self.hZServer=result[0]
......@@ -285,10 +303,7 @@ def set_start_command(value):
if __name__=='__main__':
win32serviceutil.HandleCommandLine(ZServerService)
if sys.argv[1]=='install':
if win32serviceutil.GetServiceCustomOption(ZServerService,'start') is None:
import string, os.path
home=string.split(sys.argv[0],'ZServer')[0]
command='"%s" "%s" -S' % (sys.executable, os.path.join(home,'z2.py'))
set_start_command(command)
print "Setting ZServer start command to:", command
if 'install' in sys.argv:
command='"%s" "%s" -S' % (sys.executable, os.path.join(home,'z2.py'))
set_start_command(command)
print "Setting ZServer start command to:", command
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment