def __init__(self, args): import servicemanager self.ssh = servicemanager.RegisterServiceCtrlHandler( args[0], self.ServiceCtrlHandlerEx, True) servicemanager.SetEventSourceName(self._svc_name_) self.checkPoint = 0
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) # Just say "Zope", instead of "Zope_-xxxxx" try: servicemanager.SetEventSourceName(self.evtlog_name) except AttributeError: # old pywin32 - that's ok. pass # Create an event which we will use to wait on. # The "service stop" request will set this event. # We create it inheritable so we can pass it to the child process, so # it too can act on the stop event. sa = win32security.SECURITY_ATTRIBUTES() sa.bInheritHandle = True self.hWaitStop = win32event.CreateEvent(sa, 0, 0, None) self.redirect_thread = None
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) servicemanager.SetEventSourceName(self._svc_display_name_) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) LogInfoMsg('The Flax service is initialising.') try: # Set options according to our configuration, and create the class # which manages starting and stopping the flax threads and processes. self._options = startflax.StartupOptions(main_dir=_reg.runtimepath, src_dir=_reg.runtimepath, dbs_dir=_reg.datapath) self._flax_main = startflax.FlaxMain(self._options) LogInfoMsg('The Flax service is initialised.') except: import traceback tb = traceback.format_exc() LogErrorMsg( 'Exception during initialisation, traceback follows:\n %s' % tb)
def __init__(self, args): # We get passed in the service name self._svc_name_ = args[0] # ...and from that, we can look up the other needed bits # from the registry: self._svc_display_name_ = self.getReg('DisplayName') self._svc_command_ = self.getReg('command', keyname='PythonClass') win32serviceutil.ServiceFramework.__init__(self, args) # Don't use the service name as the event source name: servicemanager.SetEventSourceName(self.evtlog_name) # Create an event which we will use to wait on. # The "service stop" request will set this event. # We create it inheritable so we can pass it to the child process, so # it too can act on the stop event. sa = win32security.SECURITY_ATTRIBUTES() sa.bInheritHandle = True self.hWaitStop = win32event.CreateEvent(sa, 0, 0, None)
msg = 'Error while calling HandleCommandLine: {}'.format(e) servicemanager.LogErrorMsg(G_program_filename + ': ' + msg) print(msg) import traceback traceback.print_exc() if len(sys.argv) > 1: msg = 'Service ' + sys.argv[1] + ' performed.' servicemanager.LogInfoMsg(G_program_filename + ': ' + msg) # do additional work needed after installation (i.e. register event message file) if len(sys.argv) > 1 and sys.argv[1] in ("install", "update"): try: servicemanager.SetEventSourceName(G_service_name, True) except Exception as e: msg = 'Failed to SetEventSourceName: {}'.format(e) servicemanager.LogErrorMsg(G_program_filename + ': ' + msg) print(msg) try: win32evtlogutil.AddSourceToRegistry(SERVICE_NAME_PREFIX + G_program_name, msgDLL=G_program_directory + MESSAGE_FILE_DLL, eventLogType="Application", eventLogFlags=None) # note: At one time I was having problems with win32evtlogutil.AddSourceToRegistry and so # I wrote my own function RegisterEventLogMessage which is preserved above in a doc string # for reference. It is no longer needed at present.