Commit 8960ead6 authored by Chris Withers's avatar Chris Withers

merge changes from Zope 2.12 branch:

- fix LP #461446: zopectl in interactive mode exited when the start/stop/etc commands were used
- zopectl status now works on Windows
- zopectl fg doesn't bomb if you hit Ctrl-C in Windows anymore.
parent 0253cdcc
...@@ -51,15 +51,16 @@ from ZConfig.datatypes import existing_dirpath ...@@ -51,15 +51,16 @@ from ZConfig.datatypes import existing_dirpath
WIN = False WIN = False
if sys.platform[:3].lower() == "win": if sys.platform[:3].lower() == "win":
WIN = True WIN = True
import pywintypes
import win32service
import win32serviceutil import win32serviceutil
from nt_svcutils import service from nt_svcutils import service
def do_windows(command): def do_windows(command):
def inner(self,arg): def inner(self,arg):
INSTANCE_HOME = self.options.directory name = self.get_service_name()
name = 'Zope'+str(hash(INSTANCE_HOME.lower())) display_name = 'Zope instance at '+self.options.directory
display_name = 'Zope instance at '+INSTANCE_HOME
# This class exists only so we can take advantage of # This class exists only so we can take advantage of
# win32serviceutil.HandleCommandLine, it is never # win32serviceutil.HandleCommandLine, it is never
...@@ -83,7 +84,8 @@ if sys.platform[:3].lower() == "win": ...@@ -83,7 +84,8 @@ if sys.platform[:3].lower() == "win":
argv=argv, argv=argv,
) )
return err,InstanceService self.InstanceClass = InstanceService
return err
return inner return inner
...@@ -220,15 +222,25 @@ class ZopeCmd(ZDCmd): ...@@ -220,15 +222,25 @@ class ZopeCmd(ZDCmd):
## START OF WINDOWS ONLY STUFF ## START OF WINDOWS ONLY STUFF
if WIN: if WIN:
def get_service_name(self):
return 'Zope'+str(hash(self.options.directory.lower()))
def get_status(self): def get_status(self):
# get_status from zdaemon relies on *nix specific socket handling. sn = self.get_service_name()
# We just don't support getting the status and sending actions to try:
# the control server on Windows. This could be extended to ask for stat = win32serviceutil.QueryServiceStatus(sn)[1]
# the status of the Windows service though self.zd_up = 1
except pywintypes.error, err:
if err[0] == 1060:
# Service not installed
stat = win32service.SERVICE_STOPPED
self.zd_up = 0 self.zd_up = 0
self.zd_pid = 0 else:
self.zd_status = None raise
return
self.zd_pid = (stat == win32service.SERVICE_RUNNING) and -1 or 0
self.zd_status = "args=%s" % self.options.program
do_start = do_windows('start') do_start = do_windows('start')
do_stop = do_windows('stop') do_stop = do_windows('stop')
...@@ -237,7 +249,7 @@ class ZopeCmd(ZDCmd): ...@@ -237,7 +249,7 @@ class ZopeCmd(ZDCmd):
# Add extra commands to install and remove the Windows service # Add extra commands to install and remove the Windows service
def do_install(self,arg): def do_install(self,arg):
err,InstanceClass = do_windows('install')(self,arg) err = do_windows('install')(self,arg)
if not err: if not err:
# If we installed successfully, put info in registry for the # If we installed successfully, put info in registry for the
# real Service class to use: # real Service class to use:
...@@ -247,12 +259,13 @@ class ZopeCmd(ZDCmd): ...@@ -247,12 +259,13 @@ class ZopeCmd(ZDCmd):
os.path.join(os.path.split(sys.argv[0])[0],'runzope'), os.path.join(os.path.split(sys.argv[0])[0],'runzope'),
self.options.configfile self.options.configfile
) )
InstanceClass.setReg('command',command) self.InstanceClass.setReg('command',command)
# This is unfortunately needed because runzope.exe is a setuptools # This is unfortunately needed because runzope.exe is a setuptools
# generated .exe that spawns off a sub process, so pid would give us # generated .exe that spawns off a sub process, so pid would give us
# the wrong event name. # the wrong event name.
InstanceClass.setReg('pid_filename',self.options.configroot.pid_filename) self.InstanceClass.setReg('pid_filename',self.options.configroot.pid_filename)
return err
def help_install(self): def help_install(self):
print "install -- Installs Zope as a Windows service." print "install -- Installs Zope as a Windows service."
...@@ -294,6 +307,8 @@ class ZopeCmd(ZDCmd): ...@@ -294,6 +307,8 @@ class ZopeCmd(ZDCmd):
command = quote_command(program) command = quote_command(program)
try: try:
return os.system(command) return os.system(command)
except KeyboardInterrupt:
pass
finally: finally:
for addition in local_additions: program.remove(addition) for addition in local_additions: program.remove(addition)
......
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