diff options
Diffstat (limited to 'win32')
| -rw-r--r-- | win32/OpenERPServerService.py | 57 | ||||
| -rw-r--r-- | win32/setup.py | 51 | ||||
| -rw-r--r-- | win32/start.bat | 7 | ||||
| -rw-r--r-- | win32/stop.bat | 5 |
4 files changed, 62 insertions, 58 deletions
diff --git a/win32/OpenERPServerService.py b/win32/OpenERPServerService.py index bf7c83e74a4..8b3c117c03d 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 (<http://tiny.be>). # @@ -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 <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## -# Win32 python extensions modules import win32serviceutil import win32service -import win32event import win32api import win32process import servicemanager @@ -30,35 +28,32 @@ import servicemanager import sys import subprocess import os -import thread + +try: + import meta +except ImportError: + if hasattr(sys, 'frozen'): + raise + from setup import generate_files + generate_files() + import meta # noqa class OpenERPServerService(win32serviceutil.ServiceFramework): # required info - _svc_name_ = "openerp-server-6.1" - _svc_display_name_ = "OpenERP Server 6.1" - # optionnal info - _svc_description_ = "OpenERP Server 6.1 service" + _svc_name_ = meta.nt_service_name + _svc_display_name_ = "%s %s" % (meta.description, meta.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 +64,19 @@ 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") + # 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... + subprocess.call(['sc', 'failure', meta.nt_service_name, 'reset=', '0', 'actions=', 'restart/0/restart/0/restart/0']) -if __name__=='__main__': +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: - diff --git a/win32/setup.py b/win32/setup.py index 2dfb8ef3493..0feedce01e0 100644 --- a/win32/setup.py +++ b/win32/setup.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # 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 <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -30,15 +30,46 @@ def datas(): r.append(("Microsoft.VC90.CRT", glob.glob('C:\Microsoft.VC90.CRT\*.*'))) return r -setup(service=["OpenERPServerService"], - options={"py2exe":{"excludes":["Tkconstants","Tkinter","tcl", - "_imagingtk","PIL._imagingtk", - "ImageTk", "PIL.ImageTk", - "FixTk"], - "skip_archive": 1, - "optimize": 2,}}, +meta = {} +execfile(os.path.join(os.path.dirname(__file__), '..', 'openerp', 'release.py'), meta) + +def generate_files(): + actions = { + 'start': ['stop', 'start'], + 'stop': ['stop'], + } + + files = [] + for action, steps in actions.items(): + fname = action + '.bat' + files.append(fname) + with open(fname, 'w') as fp: + fp.write('@PATH=%WINDIR%\system32;%WINDIR%;%WINDIR%\System32\Wbem;.\n') + for step in steps: + fp.write('@net %s %s\n' % (step, meta['nt_service_name'])) + + files.append('meta.py') + with open('meta.py', 'w') as fp: + for m in 'description serie nt_service_name'.split(): + fp.write("%s = %r\n" % (m, meta[m],)) + + return files + +excludes = "Tkconstants Tkinter tcl _imagingtk PIL._imagingtk ImageTk PIL.ImageTk FixTk".split() + +setup(service = ["OpenERPServerService"], + version = meta['version'], + license = meta['license'], + url = meta['url'], + author = meta['author'], + author_email = meta['author_email'], + data_files = generate_files(), + options = {"py2exe": { + "excludes": excludes, + "skip_archive": 1, + "optimize": 2, + }}, data_files=datas(), ) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/win32/start.bat b/win32/start.bat deleted file mode 100644 index ff3c49b1397..00000000000 --- a/win32/start.bat +++ /dev/null @@ -1,7 +0,0 @@ -@PATH=%WINDIR%\system32;%WINDIR%;%WINDIR%\System32\Wbem;.
-
-@net stop openerp-server-6.1
-
-@net start openerp-server-6.1
-
-cls
diff --git a/win32/stop.bat b/win32/stop.bat deleted file mode 100644 index 76a35b7e91f..00000000000 --- a/win32/stop.bat +++ /dev/null @@ -1,5 +0,0 @@ -@PATH=%WINDIR%\system32;%WINDIR%;%WINDIR%\System32\Wbem;.
-
-@net stop openerp-server-6.1
-
-cls
|
