forked from AceCentre/RelayKeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelaykeysd-service.py
41 lines (32 loc) · 1.11 KB
/
relaykeysd-service.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
# win32 service impl
from win32serviceutil import ServiceFramework, HandleCommandLine
from win32event import CreateEvent, SetEvent, WaitForSingleObject, WAIT_OBJECT_0
import socket
from sys import argv
import servicemanager
from win32service import SERVICE_STOP_PENDING
import relaykeysd
class RelayKeysService(ServiceFramework):
_svc_name_ = "RelayKeysDaemon"
_svc_display_name_ = "Relay Keys Daemon"
def __init__(self, args):
ServiceFramework.__init__(self, args)
self.hWaitStop = CreateEvent(None, 0, 0, None)
socket.setdefaulttimeout(60)
def _interrupt (self):
rc = WaitForSingleObject(self.hWaitStop, 0)
if rc == WAIT_OBJECT_0:
raise SystemExit()
def SvcStop(self):
self.ReportServiceStatus(SERVICE_STOP_PENDING)
SetEvent(self.hWaitStop)
def SvcDoRun(self):
relaykeysd.main(interrupt=self._interrupt)
if __name__ == '__main__':
# PyInstaller needs this
if len(argv) == 1:
servicemanager.Initialize()
servicemanager.PrepareToHostSingle(RelayKeysService)
servicemanager.StartServiceCtrlDispatcher()
else:
HandleCommandLine(RelayKeysService)