Commit 6af82bb2 by Szeberényi Imre

winservice fix

parent c88ceaa3
...@@ -27,11 +27,12 @@ logger.info("%s loaded", __file__) ...@@ -27,11 +27,12 @@ logger.info("%s loaded", __file__)
class AppServerSvc (win32serviceutil.ServiceFramework): class AppServerSvc (win32serviceutil.ServiceFramework):
_svc_name_ = "circle-agent" _svc_name_ = "circle-agent"
_svc_display_name_ = "CIRCLE Agent" _svc_display_name_ = "CIRCLE Agent"
_svc_desciption_ = "CIRCLE cloud contextualization agent"
def __init__(self, args): def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args) win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
socket.setdefaulttimeout(60) socket.setdefaulttimeout(120)
def SvcStop(self): def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
...@@ -40,15 +41,25 @@ class AppServerSvc (win32serviceutil.ServiceFramework): ...@@ -40,15 +41,25 @@ class AppServerSvc (win32serviceutil.ServiceFramework):
logger.info("%s stopped", __file__) logger.info("%s stopped", __file__)
def SvcDoRun(self): def SvcDoRun(self):
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, ''))
logger.info("%s starting", __file__) logger.info("%s starting", __file__)
agent_main() cnt = 3
while cnt > 0:
try:
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, ''))
break
except Exception as e:
logger.exception("Servicemanager busy?", e)
cnt -= 1
if cnt:
logger.info("Starting agent_main")
agent_main()
def main(): def main():
if len(sys.argv) == 1: # never happen set 1 for debugging!!!! logger.info("Started: %s", sys.argv)
if len(sys.argv) == 1:
# service must be starting... # service must be starting...
# for the sake of debugging etc, we use win32traceutil to see # for the sake of debugging etc, we use win32traceutil to see
# any unhandled exceptions and print statements. # any unhandled exceptions and print statements.
......
...@@ -31,13 +31,21 @@ def watch(): ...@@ -31,13 +31,21 @@ def watch():
def start_service(): def start_service():
win32serviceutil.StartService(service_name) win32serviceutil.StartService(service_name)
timo_base = 10
timo = timo_base
while True: while True:
if not check_service(service_name): if not check_service(service_name):
logger.info("Service %s is not running.", service_name) logger.info("Service %s is not running.", service_name)
start_service() try:
start_service()
timo = timo_base
logger.info("Service %s started.", service_name)
except Exception as e:
timo *= 2
logger.exception("Cant start service %s new timo: %s" % (service_name, timo))
if stopped: if stopped:
return return
sleep(10) sleep(timo)
class AppServerSvc (win32serviceutil.ServiceFramework): class AppServerSvc (win32serviceutil.ServiceFramework):
...@@ -65,7 +73,8 @@ class AppServerSvc (win32serviceutil.ServiceFramework): ...@@ -65,7 +73,8 @@ class AppServerSvc (win32serviceutil.ServiceFramework):
def main(): def main():
if len(sys.argv) == 1: # never happen set 1 for debugging!!!! logger.info("Started: %s", sys.argv)
if len(sys.argv) == 1:
# service must be starting... # service must be starting...
# for the sake of debugging etc, we use win32traceutil to see # for the sake of debugging etc, we use win32traceutil to see
# any unhandled exceptions and print statements. # any unhandled exceptions and print statements.
......
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 sign in to comment