Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import win32serviceutil
- import win32service
- import win32event
- import servicemanager
- import socket
- import logging
- class AppServerSvc(win32serviceutil.ServiceFramework):
- _svc_name_ = "TestService"
- _svc_display_name_ = "Test Service"
- _svc_description_ = "New Test Service"
- logging.basicConfig(filename='search_server.log', level=logging.INFO)
- logging.info('Class opened')
- def __init__(self, args):
- logging.basicConfig(filename='search_server.log', level=logging.INFO)
- logging.info('Init')
- win32serviceutil.ServiceFramework.__init__(self, args)
- self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
- socket.setdefaulttimeout(60)
- def SvcStop(self):
- logging.basicConfig(filename='search_server.log', level=logging.INFO)
- logging.info('Stop')
- self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
- win32event.SetEvent(self.hWaitStop)
- def SvcDoRun(self):
- logging.basicConfig(filename='search_server.log', level=logging.INFO)
- logging.info('Run')
- servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
- servicemanager.PYS_SERVICE_STARTED,
- (self._svc_name_, ''))
- self.main()
- def main(self):
- print("running")
- logging.basicConfig(filename='search_server.log', level=logging.INFO)
- logging.info('Main')
- if __name__ == '__main__':
- logging.basicConfig(filename='search_server.log', level=logging.INFO)
- logging.info('Calling Handle Command Line')
- win32serviceutil.HandleCommandLine(AppServerSvc)
- C:PythonScriptsSearchServer>python servicetest.py install
- Installing service TestService
- Service installed
- C:PythonScriptsSearchServer>python servicetest.py start
- Starting service TestService
- C:PythonScriptsSearchServer>python servicetest.py restart
- Restarting service TestService
- C:PythonScriptsSearchServer>python servicetest.py remove
- Removing service TestService
- Service removed
- C:PythonScriptsSearchServer>
- INFO:root:Class opened
- INFO:root:Calling Handle Command Line
- INFO:root:Class opened
- INFO:root:Calling Handle Command Line
- INFO:root:Class opened
- INFO:root:Calling Handle Command Line
- INFO:root:Class opened
- INFO:root:Calling Handle Command Line
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement