From ec58393f72bc5a73977c8d45152fb2f581b9aa9b Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 26 Nov 2012 19:12:00 +0100 Subject: [FIX] service win32: improve service: stop as same exitcode as openerp-server + auto config service to restart if exits with non-zero exitcode bzr revid: chs@openerp.com-20121126181200-01y0jqh46xsis7fb --- win32/OpenERPServerService.py | 77 ++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 38 deletions(-) (limited to 'win32/OpenERPServerService.py') diff --git a/win32/OpenERPServerService.py b/win32/OpenERPServerService.py index bf7c83e74a4..efd9243fc31 100644 --- a/win32/OpenERPServerService.py +++ b/win32/OpenERPServerService.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). # @@ -15,14 +15,12 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## -# Win32 python extensions modules import win32serviceutil import win32service -import win32event import win32api import win32process import servicemanager @@ -30,35 +28,27 @@ import servicemanager import sys import subprocess import os -import thread + +from ..openerp.release import serie class OpenERPServerService(win32serviceutil.ServiceFramework): # required info - _svc_name_ = "openerp-server-6.1" - _svc_display_name_ = "OpenERP Server 6.1" + _svc_name_ = "openerp-server-" + serie + _svc_display_name_ = "OpenERP Server " + serie # optionnal info - _svc_description_ = "OpenERP Server 6.1 service" + _svc_description_ = "OpenERP Server %s service" % (serie,) def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) - # Create an event which we will use to wait on. - # The "service stop" request will set this event. - self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) # a reference to the server's process self.terpprocess = None - # info if the service terminates correctly or if the server crashed - self.stopping = False - def SvcStop(self): # Before we do anything, tell the SCM we are starting the stop process. self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) - # stop the running TERP Server: say it's a normal exit + # stop the running OpenERP Server: say it's a normal exit win32api.TerminateProcess(int(self.terpprocess._handle), 0) servicemanager.LogInfoMsg("OpenERP Server stopped correctly") - # And set my event. - win32event.SetEvent(self.hWaitStop) - def StartTERP(self): # The server finds now its configuration automatically on Windows @@ -69,29 +59,40 @@ class OpenERPServerService(win32serviceutil.ServiceFramework): server_path = os.path.join(server_dir, 'server', 'openerp-server.exe') self.terpprocess = subprocess.Popen([server_path], cwd=server_dir, creationflags=win32process.CREATE_NO_WINDOW) - - def StartControl(self,ws): - # this listens to the Service Manager's events - win32event.WaitForSingleObject(ws, win32event.INFINITE) - self.stopping = True - def SvcDoRun(self): - # Start OpenERP Server itself self.StartTERP() - # start the loop waiting for the Service Manager's stop signal - thread.start_new_thread(self.StartControl, (self.hWaitStop,)) - # Log a info message that the server is running servicemanager.LogInfoMsg("OpenERP Server up and running") - # verification if the server is really running, else quit with an error - self.terpprocess.wait() - if not self.stopping: - sys.exit("OpenERP Server check: server not running, check the logfile for more info") - - - -if __name__=='__main__': + # exit with same exit code as OpenERP process + sys.exit(self.terpprocess.wait()) + + +def option_handler(opts): + # configure the service to auto restart on failures... + service_name = OpenERPServerService._svc_name + + hscm = win32service.OpenSCManager(None, None, win32service.SC_MANAGER_ALL_ACCESS) + try: + hs = win32serviceutil.SmartOpenService(hscm, service_name, win32service.SERVICE_ALL_ACCESS) + try: + service_failure_actions = { + 'ResetPeriod': 0, # Time in ms after which to reset the failure count to zero. + 'RebootMsg': u'', # Not using reboot option + 'Command': u'', # Not using run-command option + 'Actions': [ + (win32service.SC_ACTION_RESTART, 10), # action, delay in ms + (win32service.SC_ACTION_RESTART, 10), + (win32service.SC_ACTION_RESTART, 10), + ] + } + win32service.ChangeServiceConfig2(hs, win32service.SERVICE_CONFIG_FAILURE_ACTIONS, service_failure_actions) + finally: + win32service.CloseServiceHandle(hs) + finally: + win32service.CloseServiceHandle(hscm) + + +if __name__ == '__main__': # Do with the service whatever option is passed in the command line - win32serviceutil.HandleCommandLine(OpenERPServerService) + win32serviceutil.HandleCommandLine(OpenERPServerService, customOptionHandler=option_handler) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - -- cgit v1.2.3 From a55a26c777a0e6d9e8c49f35e6154734d3933171 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 28 Nov 2012 13:09:50 +0100 Subject: [IMP] rewrite win32/setup.py to generate dynamic files bzr revid: chs@openerp.com-20121128120950-bi6uv3bn73gotmwi --- win32/OpenERPServerService.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'win32/OpenERPServerService.py') diff --git a/win32/OpenERPServerService.py b/win32/OpenERPServerService.py index efd9243fc31..c529b582ba4 100644 --- a/win32/OpenERPServerService.py +++ b/win32/OpenERPServerService.py @@ -29,14 +29,19 @@ import sys import subprocess import os -from ..openerp.release import serie +try: + import meta +except ImportError: + if hasattr(sys, 'frozen'): + raise + from setup import generate_files + generate_files() + import meta class OpenERPServerService(win32serviceutil.ServiceFramework): # required info - _svc_name_ = "openerp-server-" + serie - _svc_display_name_ = "OpenERP Server " + serie - # optionnal info - _svc_description_ = "OpenERP Server %s service" % (serie,) + _svc_name_ = meta.nt_service_name + _svc_display_name_ = "%s %s" % (meta.description, meta.serie) def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) -- cgit v1.2.3 From 9e3a6c6cc3dd2233b82bebc79acf3f63cfd2a433 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 30 Nov 2012 12:38:28 +0100 Subject: [FIX] win32 service: configure service via sc.exe bzr revid: chs@openerp.com-20121130113828-abweveb1ryzptvhf --- win32/OpenERPServerService.py | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'win32/OpenERPServerService.py') diff --git a/win32/OpenERPServerService.py b/win32/OpenERPServerService.py index c529b582ba4..3f86c40aa4b 100644 --- a/win32/OpenERPServerService.py +++ b/win32/OpenERPServerService.py @@ -74,26 +74,29 @@ class OpenERPServerService(win32serviceutil.ServiceFramework): def option_handler(opts): # configure the service to auto restart on failures... service_name = OpenERPServerService._svc_name + restart_msg = "Restarting %s" % (OpenERPServerService._svc_display_name_,) - hscm = win32service.OpenSCManager(None, None, win32service.SC_MANAGER_ALL_ACCESS) - try: - hs = win32serviceutil.SmartOpenService(hscm, service_name, win32service.SERVICE_ALL_ACCESS) - try: - service_failure_actions = { - 'ResetPeriod': 0, # Time in ms after which to reset the failure count to zero. - 'RebootMsg': u'', # Not using reboot option - 'Command': u'', # Not using run-command option - 'Actions': [ - (win32service.SC_ACTION_RESTART, 10), # action, delay in ms - (win32service.SC_ACTION_RESTART, 10), - (win32service.SC_ACTION_RESTART, 10), - ] - } - win32service.ChangeServiceConfig2(hs, win32service.SERVICE_CONFIG_FAILURE_ACTIONS, service_failure_actions) - finally: - win32service.CloseServiceHandle(hs) - finally: - win32service.CloseServiceHandle(hscm) + subprocess.call('sc failure %s reset= 0 reboot= %r actions= reboot/0/reboot/0/reboot/0' % (service_name, restart_msg)) + + # hscm = win32service.OpenSCManager(None, None, win32service.SC_MANAGER_ALL_ACCESS) + # try: + # hs = win32serviceutil.SmartOpenService(hscm, service_name, win32service.SERVICE_ALL_ACCESS) + # try: + # service_failure_actions = { + # 'ResetPeriod': 0, # Time in ms after which to reset the failure count to zero. + # 'RebootMsg': u'', # Not using reboot option + # 'Command': u'', # Not using run-command option + # 'Actions': [ + # (win32service.SC_ACTION_RESTART, 10), # action, delay in ms + # (win32service.SC_ACTION_RESTART, 10), + # (win32service.SC_ACTION_RESTART, 10), + # ] + # } + # win32service.ChangeServiceConfig2(hs, win32service.SERVICE_CONFIG_FAILURE_ACTIONS, service_failure_actions) + # finally: + # win32service.CloseServiceHandle(hs) + # finally: + # win32service.CloseServiceHandle(hscm) if __name__ == '__main__': -- cgit v1.2.3 From b2099e17bbe4442b8353af9a72d73131404e9f9b Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 30 Nov 2012 17:12:10 +0100 Subject: [zen] Mind your words, they are important. bzr revid: chs@openerp.com-20121130161210-3ih3bnx4oc9gv2w3 --- win32/OpenERPServerService.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'win32/OpenERPServerService.py') diff --git a/win32/OpenERPServerService.py b/win32/OpenERPServerService.py index 3f86c40aa4b..ce7e21d50af 100644 --- a/win32/OpenERPServerService.py +++ b/win32/OpenERPServerService.py @@ -36,7 +36,7 @@ except ImportError: raise from setup import generate_files generate_files() - import meta + import meta # noqa class OpenERPServerService(win32serviceutil.ServiceFramework): # required info @@ -74,9 +74,8 @@ class OpenERPServerService(win32serviceutil.ServiceFramework): def option_handler(opts): # configure the service to auto restart on failures... service_name = OpenERPServerService._svc_name - restart_msg = "Restarting %s" % (OpenERPServerService._svc_display_name_,) - subprocess.call('sc failure %s reset= 0 reboot= %r actions= reboot/0/reboot/0/reboot/0' % (service_name, restart_msg)) + subprocess.call('sc failure %s reset= 0 actions= restart/0/restart/0/restart/0' % (service_name,)) # hscm = win32service.OpenSCManager(None, None, win32service.SC_MANAGER_ALL_ACCESS) # try: -- cgit v1.2.3 From 3ff3f1f87fd50d363a1a0b502a34208966b24e0a Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 30 Nov 2012 17:50:46 +0100 Subject: [FIX] win32 service: configure service via sc.exe bzr revid: chs@openerp.com-20121130165046-l1ezj4ykrhnyfzjp --- win32/OpenERPServerService.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'win32/OpenERPServerService.py') diff --git a/win32/OpenERPServerService.py b/win32/OpenERPServerService.py index ce7e21d50af..f2a6007d118 100644 --- a/win32/OpenERPServerService.py +++ b/win32/OpenERPServerService.py @@ -75,7 +75,7 @@ def option_handler(opts): # configure the service to auto restart on failures... service_name = OpenERPServerService._svc_name - subprocess.call('sc failure %s reset= 0 actions= restart/0/restart/0/restart/0' % (service_name,)) + subprocess.call(['sc', 'failure', service_name, 'reset=', '0', 'actions=', 'restart/0/restart/0/restart/0']) # hscm = win32service.OpenSCManager(None, None, win32service.SC_MANAGER_ALL_ACCESS) # try: -- cgit v1.2.3 From 9065642cc9699a39e69f5e97c5b66fb0911ffd34 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 5 Dec 2012 18:57:50 +0100 Subject: [FIX] win32 service: remove commented code bzr revid: chs@openerp.com-20121205175750-hqo058i7bp1g68rp --- win32/OpenERPServerService.py | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) (limited to 'win32/OpenERPServerService.py') diff --git a/win32/OpenERPServerService.py b/win32/OpenERPServerService.py index f2a6007d118..8b3c117c03d 100644 --- a/win32/OpenERPServerService.py +++ b/win32/OpenERPServerService.py @@ -73,30 +73,7 @@ class OpenERPServerService(win32serviceutil.ServiceFramework): def option_handler(opts): # configure the service to auto restart on failures... - service_name = OpenERPServerService._svc_name - - subprocess.call(['sc', 'failure', service_name, 'reset=', '0', 'actions=', 'restart/0/restart/0/restart/0']) - - # hscm = win32service.OpenSCManager(None, None, win32service.SC_MANAGER_ALL_ACCESS) - # try: - # hs = win32serviceutil.SmartOpenService(hscm, service_name, win32service.SERVICE_ALL_ACCESS) - # try: - # service_failure_actions = { - # 'ResetPeriod': 0, # Time in ms after which to reset the failure count to zero. - # 'RebootMsg': u'', # Not using reboot option - # 'Command': u'', # Not using run-command option - # 'Actions': [ - # (win32service.SC_ACTION_RESTART, 10), # action, delay in ms - # (win32service.SC_ACTION_RESTART, 10), - # (win32service.SC_ACTION_RESTART, 10), - # ] - # } - # win32service.ChangeServiceConfig2(hs, win32service.SERVICE_CONFIG_FAILURE_ACTIONS, service_failure_actions) - # finally: - # win32service.CloseServiceHandle(hs) - # finally: - # win32service.CloseServiceHandle(hscm) - + subprocess.call(['sc', 'failure', meta.nt_service_name, 'reset=', '0', 'actions=', 'restart/0/restart/0/restart/0']) if __name__ == '__main__': # Do with the service whatever option is passed in the command line -- cgit v1.2.3