fixed issue 265
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.3.0 (2012-12-05 09:00:19) rc1
|
Version 2.3.0 (2012-12-05 11:02:32) rc1
|
||||||
|
|||||||
+11
-11
@@ -1112,17 +1112,6 @@ def start(cron=True):
|
|||||||
pass
|
pass
|
||||||
return
|
return
|
||||||
|
|
||||||
# ## if -H cron is enabled in this *process*
|
|
||||||
# ## if --softcron use softcron
|
|
||||||
# ## use hardcron in all other cases
|
|
||||||
if cron and options.runcron and options.softcron:
|
|
||||||
print 'Using softcron (but this is not very efficient)'
|
|
||||||
global_settings.web2py_crontype = 'soft'
|
|
||||||
elif cron and options.runcron:
|
|
||||||
logger.debug('Starting hardcron...')
|
|
||||||
global_settings.web2py_crontype = 'hard'
|
|
||||||
newcron.hardcron(options.folder).start()
|
|
||||||
|
|
||||||
# ## if -W install/start/stop web2py as service
|
# ## if -W install/start/stop web2py as service
|
||||||
if options.winservice:
|
if options.winservice:
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
@@ -1137,6 +1126,17 @@ def start(cron=True):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# ## if -H cron is enabled in this *process*
|
||||||
|
# ## if --softcron use softcron
|
||||||
|
# ## use hardcron in all other cases
|
||||||
|
if cron and options.runcron and options.softcron:
|
||||||
|
print 'Using softcron (but this is not very efficient)'
|
||||||
|
global_settings.web2py_crontype = 'soft'
|
||||||
|
elif cron and options.runcron:
|
||||||
|
logger.debug('Starting hardcron...')
|
||||||
|
global_settings.web2py_crontype = 'hard'
|
||||||
|
newcron.hardcron(options.folder).start()
|
||||||
|
|
||||||
# ## if no password provided and havetk start Tk interface
|
# ## if no password provided and havetk start Tk interface
|
||||||
# ## or start interface if we want to put in taskbar (system tray)
|
# ## or start interface if we want to put in taskbar (system tray)
|
||||||
|
|
||||||
|
|||||||
+49
-8
@@ -28,6 +28,7 @@ import servicemanager
|
|||||||
import _winreg
|
import _winreg
|
||||||
from fileutils import up
|
from fileutils import up
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['web2py_windows_service_handler']
|
__all__ = ['web2py_windows_service_handler']
|
||||||
|
|
||||||
|
|
||||||
@@ -152,20 +153,60 @@ class Web2pyService(Service):
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
def web2py_windows_service_handler(argv=None, opt_file='options'):
|
class Web2pyCronService(Web2pyService):
|
||||||
|
|
||||||
|
_svc_name_ = 'web2py_cron'
|
||||||
|
_svc_display_name_ = 'web2py Cron Service'
|
||||||
|
_exe_args_ = 'options'
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
import newcron
|
||||||
|
import global_settings
|
||||||
|
self.log('web2py server starting')
|
||||||
|
if not self.chdir():
|
||||||
|
return
|
||||||
|
if len(sys.argv) == 2:
|
||||||
|
opt_mod = sys.argv[1]
|
||||||
|
else:
|
||||||
|
opt_mod = self._exe_args_
|
||||||
|
options = __import__(opt_mod, [], [], '')
|
||||||
|
global_settings.global_settings.web2py_crontype = 'external'
|
||||||
|
if options.scheduler: # -K
|
||||||
|
apps = [app.strip() for app in options.scheduler.split(
|
||||||
|
',') if check_existent_app(options, app.strip())]
|
||||||
|
else:
|
||||||
|
apps = None
|
||||||
|
self.extcron = newcron.extcron(options.folder, apps=apps)
|
||||||
|
try:
|
||||||
|
self.extcron.start()
|
||||||
|
except:
|
||||||
|
# self.server.stop()
|
||||||
|
self.extcron = None
|
||||||
|
raise
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self.log('web2py cron stopping')
|
||||||
|
if not self.chdir():
|
||||||
|
return
|
||||||
|
if self.extcron:
|
||||||
|
self.extcron.join()
|
||||||
|
|
||||||
|
def register_service_handler(
|
||||||
|
name=Web2pyService, argv=None, opt_file='options'):
|
||||||
path = os.path.dirname(__file__)
|
path = os.path.dirname(__file__)
|
||||||
web2py_path = up(path)
|
web2py_path = up(path)
|
||||||
if web2py_path.endswith('.zip'): # in case bianry distro 'library.zip'
|
if web2py_path.endswith('.zip'): # in case bianry distro 'library.zip'
|
||||||
web2py_path = os.path.dirname(web2py_path)
|
web2py_path = os.path.dirname(web2py_path)
|
||||||
os.chdir(web2py_path)
|
os.chdir(web2py_path)
|
||||||
classstring = os.path.normpath(
|
classstring = os.path.normpath(
|
||||||
os.path.join(web2py_path, 'gluon.winservice.Web2pyService'))
|
os.path.join(web2py_path, 'gluon.winservice.'+name.__name__))
|
||||||
if opt_file:
|
if opt_file:
|
||||||
Web2pyService._exe_args_ = opt_file
|
name._exe_args_ = opt_file
|
||||||
win32serviceutil.HandleCommandLine(Web2pyService,
|
win32serviceutil.HandleCommandLine(
|
||||||
serviceClassString=classstring, argv=['', 'install'])
|
name, serviceClassString=classstring, argv=['', 'install'])
|
||||||
win32serviceutil.HandleCommandLine(Web2pyService,
|
win32serviceutil.HandleCommandLine(
|
||||||
serviceClassString=classstring, argv=argv)
|
name, serviceClassString=classstring, argv=argv)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
web2py_windows_service_handler()
|
register_service_handler(Web2pyService)
|
||||||
|
register_service_handler(Web2pyCronService)
|
||||||
|
|||||||
Reference in New Issue
Block a user