4
# Script installing Tiny ERP Web Client (eTiny) as Windows service
12
WORK_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
15
p = os.environ.get('PATH', '').split(';')
18
p.insert(0, WORK_DIR+"\\python24")
19
p.insert(0, WORK_DIR+"\\python24\\Scripts")
21
os.environ['PATH'] = ';'.join(p)
23
# Win32 python extensions modules
24
import win32serviceutil
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"]
36
class TinyService(win32serviceutil.ServiceFramework):
38
_svc_name_ = "openerp-web"
39
_svc_display_name_ = "OpenERP Web"
41
_svc_description_ = "OpenERP Web Client"
43
def __init__(self, args):
44
win32serviceutil.ServiceFramework.__init__(self, args)
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)
50
# a reference to the server's process
53
# info if the service terminates correctly or if the server crashed
58
# Before we do anything, tell the SCM we are starting the stop process.
59
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
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.")
66
win32event.SetEvent(self.hWaitStop)
68
def StartService(self):
70
self.proc = subprocess.Popen(EXECUTABLE, cwd=WORK_DIR,
71
creationflags=win32process.CREATE_NO_WINDOW)
73
def StartControl(self,ws):
74
# this listens to the Service Manager's events
75
win32event.WaitForSingleObject(ws, win32event.INFINITE)
80
# Start the service itself
83
# start the loop waiting for the Service Manager's stop signal
84
thread.start_new_thread(self.StartControl, (self.hWaitStop,))
86
# Log a info message that the server is running
87
servicemanager.LogInfoMsg(TinyService._svc_display_name_ + " is up and running.")
89
# verification if the server is really running, else quit with an error
93
sys.exit(TinyService._svc_display_name_ + " is not running, check the logfile for more info.")
95
if __name__=='__main__':
96
# Do with the service whatever option is passed in the command line
97
win32serviceutil.HandleCommandLine(TinyService)