Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import win32service
- import win32serviceutil
- import win32api
- import win32con
- import win32event
- import win32evtlogutil
- import os, sys, string, time
- import traceback
- import config
- import logging
- from MySQL_handler import MySQLHandler
- class NLUService(win32serviceutil.ServiceFramework):
- _svc_name_ = "NLU_Triage"
- _svc_display_name_ = "NLU Triage Service"
- def __init__(self, args):
- win32serviceutil.ServiceFramework.__init__(self, args)
- self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
- DBHandler=MySQLHandler()
- logging.getLogger('').addHandler(DBHandler)
- def SvcStop(self):
- self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
- win32event.SetEvent(self.hWaitStop)
- def SvcDoRun(self):
- import servicemanager
- servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,servicemanager.PYS_SERVICE_STARTED,(self._svc_name_, ''))
- self.timeout = 10000 # This is how long the service will wait to run / refresh itself (milliseconds)
- while 1:
- # Wait for service stop signal, if I timeout, loop again
- rc = win32event.WaitForSingleObject(self.hWaitStop, self.timeout)
- # Check to see if self.hWaitStop happened
- if rc == win32event.WAIT_OBJECT_0:
- # Stop signal encountered
- servicemanager.LogInfoMsg("NLU_Triage - STOPPED!") #For Event Log
- break
- else:
- #[actual service code between rests]
- try:
- logging.info("Starting NLU Triage Process...")
- file_path = "D:\\NLU Triage\\hf_triage.py"
- execfile(file_path) #Execute the script
- logging.info("NLU Triage Process finished")
- except:
- logging.error(traceback.format_exc())
- def ctrlHandler(ctrlType):
- return True
- if __name__ == '__main__':
- win32api.SetConsoleCtrlHandler(ctrlHandler, True)
- win32serviceutil.HandleCommandLine(NLUService)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement