66import os
77import sys
88
9- # import socket
10- # import time
119import logging
1210
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-
2511from threading import Thread
2612from mamonsu .lib .config import Config
2713from mamonsu .lib .supervisor import Supervisor
2814
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
3416
3517class MamonsuSvc (win32serviceutil .ServiceFramework ):
3618
@@ -49,38 +31,20 @@ def SvcStop(self):
4931
5032 def SvcDoRun (self ):
5133
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-
6334 win32evtlogutil .ReportEvent (
6435 self ._svc_name_ ,
6536 servicemanager .PYS_SERVICE_STARTED ,
6637 0 ,
6738 servicemanager .EVENTLOG_INFORMATION_TYPE ,
6839 (self ._svc_name_ , '' ))
6940
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')
7741 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_ , '' ))
8448
8549 thread = Thread (target = supervisor .start )
8650 thread .daemon = True
@@ -102,6 +66,17 @@ def SvcDoRun(self):
10266# win32serviceutil.HandleCommandLine(MamonsuSvc)
10367
10468if __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+
10580 if len (sys .argv ) == 1 :
10681 servicemanager .Initialize ()
10782 servicemanager .PrepareToHostSingle (MamonsuSvc )
0 commit comments