~openerp-commiter/openobject-client-web/OOCRM

« back to all changes in this revision

Viewing changes to win32/OpenERPWebService.py

  • Committer: ame (Tiny/Axelor)
  • Date: 2009-01-07 05:36:41 UTC
  • Revision ID: ame@tinyerp.com-20090107053641-9hanwak1pgz7etow
* Windows Installer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# etiny-service.py
 
3
#
 
4
# Script installing Tiny ERP Web Client (eTiny) as Windows service
 
5
 
 
6
import os
 
7
import sys
 
8
import thread
 
9
import subprocess
 
10
 
 
11
# Working Directory
 
12
WORK_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
13
 
 
14
# Update PATH
 
15
p = os.environ.get('PATH', '').split(';')
 
16
 
 
17
p.insert(0, WORK_DIR)
 
18
p.insert(0, WORK_DIR+"\\python24")
 
19
p.insert(0, WORK_DIR+"\\python24\\Scripts")
 
20
 
 
21
os.environ['PATH'] = ';'.join(p)
 
22
 
 
23
# Win32 python extensions modules
 
24
import win32serviceutil
 
25
import win32service
 
26
import win32event
 
27
import win32api
 
28
import win32con
 
29
import win32process
 
30
import servicemanager
 
31
 
 
32
# The command itself
 
33
#EXECUTABLE = ["start-openerp-web.exe", "--config", "conf\openerp-web.cfg"]
 
34
EXECUTABLE = ["python.exe", "python24\Scripts\start-openerp-web-script.py", "--config", "conf\openerp-web.cfg"]
 
35
 
 
36
class TinyService(win32serviceutil.ServiceFramework):
 
37
    
 
38
    _svc_name_ = "openerp-web"
 
39
    _svc_display_name_ = "OpenERP Web"
 
40
 
 
41
    _svc_description_ = "OpenERP Web Client"
 
42
 
 
43
    def __init__(self, args):
 
44
        win32serviceutil.ServiceFramework.__init__(self, args)
 
45
 
 
46
        # Create an event which we will use to wait on.
 
47
        # The "service stop" request will set this event.
 
48
        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
 
49
 
 
50
        # a reference to the server's process
 
51
        self.proc = None
 
52
        
 
53
        # info if the service terminates correctly or if the server crashed
 
54
        self.stopping = False
 
55
 
 
56
 
 
57
    def SvcStop(self):
 
58
        # Before we do anything, tell the SCM we are starting the stop process.
 
59
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
 
60
 
 
61
        # stop the running TERP Server: say it's a normal exit
 
62
        win32api.TerminateProcess(int(self.proc._handle), 0)
 
63
        servicemanager.LogInfoMsg(TinyService._svc_display_name_ + " stopped correctly.")
 
64
 
 
65
        # And set my event.
 
66
        win32event.SetEvent(self.hWaitStop)
 
67
 
 
68
    def StartService(self):
 
69
 
 
70
        self.proc = subprocess.Popen(EXECUTABLE, cwd=WORK_DIR,
 
71
                                     creationflags=win32process.CREATE_NO_WINDOW)
 
72
 
 
73
    def StartControl(self,ws):
 
74
        # this listens to the Service Manager's events
 
75
        win32event.WaitForSingleObject(ws, win32event.INFINITE)
 
76
        self.stopping = True
 
77
 
 
78
    def SvcDoRun(self):
 
79
    
 
80
        # Start the service itself
 
81
        self.StartService()
 
82
 
 
83
        # start the loop waiting for the Service Manager's stop signal
 
84
        thread.start_new_thread(self.StartControl, (self.hWaitStop,))
 
85
    
 
86
        # Log a info message that the server is running
 
87
        servicemanager.LogInfoMsg(TinyService._svc_display_name_ + " is up and running.")
 
88
    
 
89
        # verification if the server is really running, else quit with an error
 
90
        self.proc.wait()
 
91
 
 
92
        if not self.stopping:
 
93
            sys.exit(TinyService._svc_display_name_ + " is not running, check the logfile for more info.")
 
94
 
 
95
if __name__=='__main__':
 
96
    # Do with the service whatever option is passed in the command line
 
97
    win32serviceutil.HandleCommandLine(TinyService)
 
98