6
6
import os
7
7
import sys
8
8
9
- # import socket
10
- # import time
11
9
import logging
12
10
13
- # import socket
14
- # import os
15
- # import sys
16
- # import glob
17
- # import time
18
- # import traceback
19
- # import json
20
- # import threading
21
- # import signal
22
- # import codecs
23
- # import re
24
-
25
11
from threading import Thread
26
12
from mamonsu .lib .config import Config
27
13
from mamonsu .lib .supervisor import Supervisor
28
14
29
- # logging.basicConfig(
30
- # filename = 'c:\\Temp\\hello-service.log',
31
- # level = logging.DEBUG,
32
- # format = '[helloworld-service] %(levelname)-7.7s %(message)s'
33
- # )
15
+ config = None
34
16
35
17
class MamonsuSvc (win32serviceutil .ServiceFramework ):
36
18
@@ -49,38 +31,20 @@ def SvcStop(self):
49
31
50
32
def SvcDoRun (self ):
51
33
52
-
53
-
54
- # determine if application is a script file or frozen exe
55
- if getattr (sys , 'frozen' , False ):
56
- exe_dir = os .path .dirname (sys .executable )
57
- elif __file__ :
58
- # exe_dir = C:\WINDOWS\system32 for service
59
- exe_dir = os .path .dirname (os .path .abspath (__file__ ))
60
-
61
- logging .info ("exe_dir=" + exe_dir )
62
-
63
34
win32evtlogutil .ReportEvent (
64
35
self ._svc_name_ ,
65
36
servicemanager .PYS_SERVICE_STARTED ,
66
37
0 ,
67
38
servicemanager .EVENTLOG_INFORMATION_TYPE ,
68
39
(self ._svc_name_ , '' ))
69
40
70
- # logging.basicConfig( filename = os.path.join(exe_dir, 'agent.log'), level = logging.DEBUG, format = '[helloworld-service] %(levelname)-7.7s %(message)s' )
71
-
72
- # config_file = os.path.join(exe_dir, 'agent_win32.conf')
73
- config_file = os .path .join (exe_dir , 'agent.conf' )
74
- logging .info (config_file )
75
- config = Config (config_file )
76
- # config = Config('c:\\mamonsu\\agent_win32.conf')
77
41
supervisor = Supervisor (config )
78
- # win32evtlogutil.ReportEvent(
79
- # self._svc_name_,
80
- # servicemanager.PYS_SERVICE_STOPPED,
81
- # 0,
82
- # servicemanager.EVENTLOG_INFORMATION_TYPE,
83
- # (self._svc_name_, ''))
42
+ win32evtlogutil .ReportEvent (
43
+ self ._svc_name_ ,
44
+ servicemanager .PYS_SERVICE_STOPPED ,
45
+ 0 ,
46
+ servicemanager .EVENTLOG_INFORMATION_TYPE ,
47
+ (self ._svc_name_ , '' ))
84
48
85
49
thread = Thread (target = supervisor .start )
86
50
thread .daemon = True
@@ -102,6 +66,17 @@ def SvcDoRun(self):
102
66
# win32serviceutil.HandleCommandLine(MamonsuSvc)
103
67
104
68
if __name__ == '__main__' :
69
+ # determine if application is a script file or frozen exe
70
+ if getattr (sys , 'frozen' , False ):
71
+ exe_dir = os .path .dirname (sys .executable )
72
+ elif __file__ :
73
+ # exe_dir = C:\WINDOWS\system32 for service
74
+ exe_dir = os .path .dirname (os .path .abspath (__file__ ))
75
+
76
+ # initializing in this place for logging
77
+ config_file = os .path .join (exe_dir , 'agent.conf' )
78
+ config = Config (config_file )
79
+
105
80
if len (sys .argv ) == 1 :
106
81
servicemanager .Initialize ()
107
82
servicemanager .PrepareToHostSingle (MamonsuSvc )
0 commit comments