~openerp-community/openobject-server/fix-1130010-toxml-escape-quot

1864 by pap(openerp)
Changed encoding to coding ref: PEP: 0263
1
# -*- coding: utf-8 -*-
1230 by Christophe Simonis
passing in GPL-3
2
##############################################################################
4357.2.64 by Christophe Simonis
[FIX] service win32: improve service: stop as same exitcode as openerp-server + auto config service to restart if exits with non-zero exitcode
3
#
1861 by PSO(OpenERP)
Changed licencing
4
#    OpenERP, Open Source Management Solution
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
1230 by Christophe Simonis
passing in GPL-3
6
#
7
#    This program is free software: you can redistribute it and/or modify
1861 by PSO(OpenERP)
Changed licencing
8
#    it under the terms of the GNU Affero General Public License as
9
#    published by the Free Software Foundation, either version 3 of the
10
#    License, or (at your option) any later version.
1230 by Christophe Simonis
passing in GPL-3
11
#
12
#    This program is distributed in the hope that it will be useful,
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1861 by PSO(OpenERP)
Changed licencing
15
#    GNU Affero General Public License for more details.
1230 by Christophe Simonis
passing in GPL-3
16
#
1861 by PSO(OpenERP)
Changed licencing
17
#    You should have received a copy of the GNU Affero General Public License
4357.2.64 by Christophe Simonis
[FIX] service win32: improve service: stop as same exitcode as openerp-server + auto config service to restart if exits with non-zero exitcode
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
1230 by Christophe Simonis
passing in GPL-3
19
#
20
##############################################################################
21
1861 by PSO(OpenERP)
Changed licencing
22
import win32serviceutil
23
import win32service
24
import win32api
25
import win32process
26
import servicemanager
27
28
import sys
29
import subprocess
30
import os
4357.2.64 by Christophe Simonis
[FIX] service win32: improve service: stop as same exitcode as openerp-server + auto config service to restart if exits with non-zero exitcode
31
4357.2.66 by Christophe Simonis
[IMP] rewrite win32/setup.py to generate dynamic files
32
try:
33
    import meta
34
except ImportError:
35
    if hasattr(sys, 'frozen'):
36
        raise
37
    from setup import generate_files
38
    generate_files()
4357.2.78 by Christophe Simonis
[zen] Mind your words, they are important.
39
    import meta     # noqa
1861 by PSO(OpenERP)
Changed licencing
40
41
class OpenERPServerService(win32serviceutil.ServiceFramework):
42
    # required info
4357.2.66 by Christophe Simonis
[IMP] rewrite win32/setup.py to generate dynamic files
43
    _svc_name_ = meta.nt_service_name
44
    _svc_display_name_ = "%s %s" % (meta.description, meta.serie)
1861 by PSO(OpenERP)
Changed licencing
45
46
    def __init__(self, args):
47
        win32serviceutil.ServiceFramework.__init__(self, args)
48
        # a reference to the server's process
49
        self.terpprocess = None
50
51
    def SvcStop(self):
52
        # Before we do anything, tell the SCM we are starting the stop process.
53
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
4357.2.64 by Christophe Simonis
[FIX] service win32: improve service: stop as same exitcode as openerp-server + auto config service to restart if exits with non-zero exitcode
54
        # stop the running OpenERP Server: say it's a normal exit
1861 by PSO(OpenERP)
Changed licencing
55
        win32api.TerminateProcess(int(self.terpprocess._handle), 0)
56
        servicemanager.LogInfoMsg("OpenERP Server stopped correctly")
57
58
    def StartTERP(self):
59
        # The server finds now its configuration automatically on Windows
60
        # We start the ERP Server as an independent process, but we keep its handle
61
        # The server's binary must be one directory above the service's binary (when py2exe'd the python libraries shouldn' mix)
62
        service_dir = os.path.dirname(sys.argv[0])
63
        server_dir = os.path.split(service_dir)[0]
3907 by Stephane Wirtel
[FIX] Set the right directory in the service, set the right version
64
        server_path = os.path.join(server_dir, 'server', 'openerp-server.exe')
1861 by PSO(OpenERP)
Changed licencing
65
        self.terpprocess = subprocess.Popen([server_path], cwd=server_dir, creationflags=win32process.CREATE_NO_WINDOW)
66
1197.1.11 by Stephane Wirtel
Indent bugfix
67
    def SvcDoRun(self):
1861 by PSO(OpenERP)
Changed licencing
68
        self.StartTERP()
69
        servicemanager.LogInfoMsg("OpenERP Server up and running")
4357.2.64 by Christophe Simonis
[FIX] service win32: improve service: stop as same exitcode as openerp-server + auto config service to restart if exits with non-zero exitcode
70
        # exit with same exit code as OpenERP process
71
        sys.exit(self.terpprocess.wait())
72
73
74
def option_handler(opts):
75
    # configure the service to auto restart on failures...
4357.2.86 by Christophe Simonis
[FIX] win32 service: remove commented code
76
    subprocess.call(['sc', 'failure', meta.nt_service_name, 'reset=', '0', 'actions=', 'restart/0/restart/0/restart/0'])
4357.2.64 by Christophe Simonis
[FIX] service win32: improve service: stop as same exitcode as openerp-server + auto config service to restart if exits with non-zero exitcode
77
78
if __name__ == '__main__':
1861 by PSO(OpenERP)
Changed licencing
79
    # Do with the service whatever option is passed in the command line
4357.2.64 by Christophe Simonis
[FIX] service win32: improve service: stop as same exitcode as openerp-server + auto config service to restart if exits with non-zero exitcode
80
    win32serviceutil.HandleCommandLine(OpenERPServerService, customOptionHandler=option_handler)
923 by Christophe Simonis
add encoding comment and vim comment
81
82
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: