2009-10-20 10:52:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-11-03 18:27:16 +00:00
|
|
|
##############################################################################
|
2012-11-26 18:12:00 +00:00
|
|
|
#
|
2009-10-14 12:32:15 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
2008-11-03 18:27:16 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 12:32:15 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2008-11-03 18:27:16 +00:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 12:32:15 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2008-11-03 18:27:16 +00:00
|
|
|
#
|
2009-10-14 12:32:15 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2012-11-26 18:12:00 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-11-03 18:27:16 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2009-10-14 12:32:15 +00:00
|
|
|
import win32serviceutil
|
|
|
|
import win32service
|
|
|
|
import win32api
|
|
|
|
import win32process
|
|
|
|
import servicemanager
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import os
|
2012-11-26 18:12:00 +00:00
|
|
|
|
2012-11-28 12:09:50 +00:00
|
|
|
try:
|
|
|
|
import meta
|
|
|
|
except ImportError:
|
|
|
|
if hasattr(sys, 'frozen'):
|
|
|
|
raise
|
|
|
|
from setup import generate_files
|
|
|
|
generate_files()
|
2012-11-30 16:12:10 +00:00
|
|
|
import meta # noqa
|
2009-10-14 12:32:15 +00:00
|
|
|
|
|
|
|
class OpenERPServerService(win32serviceutil.ServiceFramework):
|
|
|
|
# required info
|
2012-11-28 12:09:50 +00:00
|
|
|
_svc_name_ = meta.nt_service_name
|
|
|
|
_svc_display_name_ = "%s %s" % (meta.description, meta.serie)
|
2009-10-14 12:32:15 +00:00
|
|
|
|
|
|
|
def __init__(self, args):
|
|
|
|
win32serviceutil.ServiceFramework.__init__(self, args)
|
|
|
|
# a reference to the server's process
|
|
|
|
self.terpprocess = None
|
|
|
|
|
|
|
|
def SvcStop(self):
|
|
|
|
# Before we do anything, tell the SCM we are starting the stop process.
|
|
|
|
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
|
2012-11-26 18:12:00 +00:00
|
|
|
# stop the running OpenERP Server: say it's a normal exit
|
2009-10-14 12:32:15 +00:00
|
|
|
win32api.TerminateProcess(int(self.terpprocess._handle), 0)
|
|
|
|
servicemanager.LogInfoMsg("OpenERP Server stopped correctly")
|
|
|
|
|
|
|
|
def StartTERP(self):
|
|
|
|
# The server finds now its configuration automatically on Windows
|
|
|
|
# We start the ERP Server as an independent process, but we keep its handle
|
|
|
|
# The server's binary must be one directory above the service's binary (when py2exe'd the python libraries shouldn' mix)
|
|
|
|
service_dir = os.path.dirname(sys.argv[0])
|
|
|
|
server_dir = os.path.split(service_dir)[0]
|
2011-12-21 17:38:33 +00:00
|
|
|
server_path = os.path.join(server_dir, 'server', 'openerp-server.exe')
|
2009-10-14 12:32:15 +00:00
|
|
|
self.terpprocess = subprocess.Popen([server_path], cwd=server_dir, creationflags=win32process.CREATE_NO_WINDOW)
|
|
|
|
|
2008-10-27 13:10:16 +00:00
|
|
|
def SvcDoRun(self):
|
2009-10-14 12:32:15 +00:00
|
|
|
self.StartTERP()
|
|
|
|
servicemanager.LogInfoMsg("OpenERP Server up and running")
|
2012-11-26 18:12:00 +00:00
|
|
|
# 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...
|
2012-12-05 17:57:50 +00:00
|
|
|
subprocess.call(['sc', 'failure', meta.nt_service_name, 'reset=', '0', 'actions=', 'restart/0/restart/0/restart/0'])
|
2012-11-26 18:12:00 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2009-10-14 12:32:15 +00:00
|
|
|
# Do with the service whatever option is passed in the command line
|
2012-11-26 18:12:00 +00:00
|
|
|
win32serviceutil.HandleCommandLine(OpenERPServerService, customOptionHandler=option_handler)
|
2008-07-23 15:01:27 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|