2009-10-20 10:52:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-11-03 18:27:16 +00:00
|
|
|
|
2014-09-02 12:02:37 +00:00
|
|
|
import servicemanager
|
2009-10-14 12:32:15 +00:00
|
|
|
import win32api
|
|
|
|
import win32process
|
2014-09-02 12:02:37 +00:00
|
|
|
import win32service
|
|
|
|
import win32serviceutil
|
2009-10-14 12:32:15 +00:00
|
|
|
|
|
|
|
import subprocess
|
2014-09-02 12:02:37 +00:00
|
|
|
import sys
|
|
|
|
from os.path import dirname, join, split
|
|
|
|
|
|
|
|
|
|
|
|
execfile(join(dirname(__file__), '..', 'server', 'openerp', 'release.py'))
|
2012-11-26 18:12:00 +00:00
|
|
|
|
2009-10-14 12:32:15 +00:00
|
|
|
|
2014-09-02 12:02:37 +00:00
|
|
|
class OdooService(win32serviceutil.ServiceFramework):
|
|
|
|
_svc_name_ = nt_service_name
|
|
|
|
_svc_display_name_ = "%s %s" % (nt_service_name, serie)
|
2009-10-14 12:32:15 +00:00
|
|
|
|
|
|
|
def __init__(self, args):
|
|
|
|
win32serviceutil.ServiceFramework.__init__(self, args)
|
2014-09-02 12:02:37 +00:00
|
|
|
self.odooprocess = None # Reference to the server's process
|
2009-10-14 12:32:15 +00:00
|
|
|
|
|
|
|
def SvcStop(self):
|
|
|
|
# Before we do anything, tell the SCM we are starting the stop process.
|
|
|
|
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
|
2014-09-02 12:02:37 +00:00
|
|
|
# Stop the running Odoo: say it's a normal exit
|
|
|
|
win32api.TerminateProcess(int(self.odooprocess._handle), 0)
|
|
|
|
servicemanager.LogInfoMsg("Odoo stopped correctly")
|
2009-10-14 12:32:15 +00:00
|
|
|
|
2008-10-27 13:10:16 +00:00
|
|
|
def SvcDoRun(self):
|
2014-09-02 12:02:37 +00:00
|
|
|
# We start Odoo as an independent process, but we keep its handle
|
|
|
|
service_dir = dirname(sys.argv[0])
|
|
|
|
server_dir = split(service_dir)[0]
|
|
|
|
server_path = join(server_dir, 'server', 'openerp-server.exe')
|
|
|
|
self.odooprocess = subprocess.Popen(
|
|
|
|
[server_path], cwd=server_dir, creationflags=win32process.CREATE_NO_WINDOW
|
|
|
|
)
|
|
|
|
servicemanager.LogInfoMsg('Odoo up and running')
|
|
|
|
# exit with same exit code as Odoo process
|
|
|
|
sys.exit(self.odooprocess.wait())
|
2012-11-26 18:12:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def option_handler(opts):
|
|
|
|
# configure the service to auto restart on failures...
|
2014-09-02 12:02:37 +00:00
|
|
|
subprocess.call([
|
|
|
|
'sc', 'failure', nt_service_name, 'reset=', '0', 'actions=', 'restart/0/restart/0/restart/0'
|
|
|
|
])
|
2012-11-26 18:12:00 +00:00
|
|
|
|
2008-07-23 15:01:27 +00:00
|
|
|
|
2014-09-02 12:02:37 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
win32serviceutil.HandleCommandLine(OdooService, customOptionHandler=option_handler)
|