-
Notifications
You must be signed in to change notification settings - Fork 625
/
PlexConnect_WinService.py
executable file
·52 lines (35 loc) · 1.33 KB
/
PlexConnect_WinService.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
PlexConnect_WinService
Starter script to run PlexConnect as a Windows Service
prerequisites:
http://sourceforge.net/projects/pywin32/
usage:
python PlexConnect_WinService.py <command>
with <command> = install, start, stop or remove
sources:
http://stackoverflow.com/questions/32404/can-i-run-a-python-script-as-a-service-in-windows-how
http://code.activestate.com/recipes/551780/
http://docs.activestate.com/activepython/2.4/pywin32/win32service.html
...and others
"""
import win32serviceutil
import win32service
import PlexConnect
class AppServerSvc(win32serviceutil.ServiceFramework):
_svc_name_ = "PlexConnect-Service"
_svc_display_name_ = "PlexConnect-Service"
_svc_description_ = "Description"
def __init__(self,args):
win32serviceutil.ServiceFramework.__init__(self,args)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
PlexConnect.cmdShutdown()
def SvcDoRun(self):
self.ReportServiceStatus(win32service.SERVICE_RUNNING)
running = PlexConnect.startup()
while running:
running = PlexConnect.run(timeout=10)
PlexConnect.shutdown()
self.ReportServiceStatus(win32service.SERVICE_STOPPED)
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(AppServerSvc)