Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. import win32serviceutil
  2. import win32service
  3. import win32event
  4. import servicemanager
  5. import socket
  6. import logging
  7.  
  8.  
  9. class AppServerSvc(win32serviceutil.ServiceFramework):
  10. _svc_name_ = "TestService"
  11. _svc_display_name_ = "Test Service"
  12. _svc_description_ = "New Test Service"
  13.  
  14. logging.basicConfig(filename='search_server.log', level=logging.INFO)
  15. logging.info('Class opened')
  16.  
  17. def __init__(self, args):
  18. logging.basicConfig(filename='search_server.log', level=logging.INFO)
  19. logging.info('Init')
  20. win32serviceutil.ServiceFramework.__init__(self, args)
  21. self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
  22. socket.setdefaulttimeout(60)
  23.  
  24.  
  25. def SvcStop(self):
  26. logging.basicConfig(filename='search_server.log', level=logging.INFO)
  27. logging.info('Stop')
  28. self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
  29. win32event.SetEvent(self.hWaitStop)
  30.  
  31.  
  32. def SvcDoRun(self):
  33. logging.basicConfig(filename='search_server.log', level=logging.INFO)
  34. logging.info('Run')
  35. servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
  36. servicemanager.PYS_SERVICE_STARTED,
  37. (self._svc_name_, ''))
  38. self.main()
  39.  
  40.  
  41. def main(self):
  42. print("running")
  43. logging.basicConfig(filename='search_server.log', level=logging.INFO)
  44. logging.info('Main')
  45.  
  46.  
  47. if __name__ == '__main__':
  48. logging.basicConfig(filename='search_server.log', level=logging.INFO)
  49. logging.info('Calling Handle Command Line')
  50. win32serviceutil.HandleCommandLine(AppServerSvc)
  51.  
  52. C:PythonScriptsSearchServer>python servicetest.py install
  53. Installing service TestService
  54. Service installed
  55.  
  56. C:PythonScriptsSearchServer>python servicetest.py start
  57. Starting service TestService
  58.  
  59. C:PythonScriptsSearchServer>python servicetest.py restart
  60. Restarting service TestService
  61.  
  62. C:PythonScriptsSearchServer>python servicetest.py remove
  63. Removing service TestService
  64. Service removed
  65.  
  66. C:PythonScriptsSearchServer>
  67.  
  68. INFO:root:Class opened
  69. INFO:root:Calling Handle Command Line
  70. INFO:root:Class opened
  71. INFO:root:Calling Handle Command Line
  72. INFO:root:Class opened
  73. INFO:root:Calling Handle Command Line
  74. INFO:root:Class opened
  75. INFO:root:Calling Handle Command Line
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement