def shutdown(a=None, b=None): """ Function to shut down the client. """ global loop env = Environment.getInstance() env.log.info("GOsa DBUS is shutting down") # Shutdown plugins PluginRegistry.shutdown() if loop: loop.quit() logging.shutdown() exit(0)
def shutdown(a=None, b=None): env = Environment.getInstance() # Function to shut down the client. Do some clean up and close sockets. amqp = PluginRegistry.getInstance("AMQPClientHandler") # Tell others that we're away now e = EventMaker() goodbye = e.Event(e.ClientLeave(e.Id(env.uuid))) amqp.sendEvent(goodbye) # Shutdown plugins PluginRegistry.shutdown() logging.shutdown() exit(0)
def shutdown(a=None, b=None): global dr env = Environment.getInstance() log = logging.getLogger(__name__) # Function to shut down the client. Do some clean up and close sockets. # Function to shut down the client. Do some clean up and close sockets. mqtt = PluginRegistry.getInstance("MQTTClientHandler") # Tell others that we're away now e = EventMaker() goodbye = e.Event(e.ClientLeave(e.Id(env.uuid))) if mqtt: log.info("sending ClientLeave") mqtt.send_event(goodbye, qos=1) # Shutdown plugins PluginRegistry.shutdown() #TODO: remove this hack wait = 1 for t in env.threads: if t.isAlive(): log.warning("thread %s still alive" % t.getName()) if hasattr(t, 'stop'): log.warning("calling 'stop' for thread %s" % t.getName()) t.stop() if hasattr(t, 'cancel'): log.warning("calling 'cancel' for thread %s" % t.getName()) t.cancel() t.join(wait) if t.is_alive(): try: log.warning("calling built in 'stop' for thread %s" % t.getName()) t._stop() except: log.error("could not stop thread %s" % t.getName()) dr.stop() log.info("shut down") logging.shutdown()
def shutdown(a=None, b=None): global dr env = Environment.getInstance() log = logging.getLogger(__name__) # Function to shut down the client. Do some clean up and close sockets. mqtt = PluginRegistry.getInstance("MQTTClientHandler") # Tell others that we're away now e = EventMaker() goodbye = e.Event(e.ClientLeave(e.Id(env.uuid))) if mqtt: mqtt.send_event(goodbye) mqtt.close() # Shutdown plugins PluginRegistry.shutdown() #TODO: remove this hack wait = 1 for t in env.threads: if t.isAlive(): log.warning("thread %s still alive" % t.getName()) if hasattr(t, 'stop'): log.warning("calling 'stop' for thread %s" % t.getName()) t.stop() if hasattr(t, 'cancel'): log.warning("calling 'cancel' for thread %s" % t.getName()) t.cancel() t.join(wait) if t.is_alive(): try: log.warning("calling built in 'stop' for thread %s" % t.getName()) t._stop() except: log.error("could not stop thread %s" % t.getName()) dr.stop() log.info("shut down") logging.shutdown()
def mainLoop(env): global netstate, dr # Enable DBus runner dr = DBusRunner() dr.start() # Do network monitoring nm = Monitor(netactivity) netactivity(nm.is_online()) """ Main event loop which will process all registered threads in a loop. It will run as long env.active is set to True.""" try: log = logging.getLogger(__name__) while True: # Check netstate and wait until we're back online if not netstate: log.info("waiting for network connectivity") while not netstate: time.sleep(1) # Load plugins PluginRegistry(component='gosa.client.module') # Sleep and slice wait = 2 while True: # Threading doesn't seem to work well with python... for p in env.threads: # Bail out if we're active in the meanwhile if not env.active: break p.join(wait) # No break, go to main loop else: continue # Break, leave main loop break # Break, leave main loop if not env.reset_requested: break # Wait for threads to shut down for t in env.threads: if hasattr(t, 'stop'): t.stop() if hasattr(t, 'cancel'): t.cancel() t.join(wait) #TODO: remove me if t.is_alive(): try: t._stop() except: print(str(t.getName()) + ' could not be terminated') # Lets do an environment reset now PluginRegistry.shutdown() # Make us active and loop from the beginning env.reset_requested = False env.active = True if not netstate: log.info("waiting for network connectivity") while not netstate: time.sleep(1) sleep = randint(30, 60) env.log.info("waiting %s seconds to try an MQTT connection recovery" % sleep) time.sleep(sleep) except Exception as detail: log.critical("unexpected error in mainLoop") log.exception(detail) log.debug(traceback.format_exc()) except KeyboardInterrupt: log.info("console requested shutdown") finally: shutdown()
def mainLoop(env): global netstate, dr # Enable DBus runner dr = DBusRunner() dr.start() # Do network monitoring nm = Monitor(netactivity) netactivity(nm.is_online()) """ Main event loop which will process all registered threads in a loop. It will run as long env.active is set to True.""" try: log = logging.getLogger(__name__) while True: # Check netstate and wait until we're back online if not netstate: log.info("waiting for network connectivity") while not netstate: time.sleep(1) # Load plugins PluginRegistry(component='gosa.client.module') # Sleep and slice wait = 2 while True: # Threading doesn't seem to work well with python... for p in env.threads: # Bail out if we're active in the meanwhile if not env.active: break p.join(wait) # No break, go to main loop else: continue # Break, leave main loop break # Break, leave main loop if not env.reset_requested: break # Wait for threads to shut down for t in env.threads: if hasattr(t, 'stop'): t.stop() if hasattr(t, 'cancel'): t.cancel() t.join(wait) #TODO: remove me if t.is_alive(): try: t._stop() except: print(str(t.getName()) + ' could not be terminated') # Lets do an environment reset now PluginRegistry.shutdown() # Make us active and loop from the beginning env.reset_requested = False env.active = True if not netstate: log.info("waiting for network connectivity") while not netstate: time.sleep(1) sleep = randint(30, 60) env.log.info( "waiting %s seconds to try an MQTT connection recovery" % sleep) time.sleep(sleep) except Exception as detail: log.critical("unexpected error in mainLoop") log.exception(detail) log.debug(traceback.format_exc()) except KeyboardInterrupt: log.info("console requested shutdown") finally: shutdown()
def SvcDoRun(self): pythoncom.CoInitialize() servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STARTED, (self._svc_name_, '')) # Start main loop thread here Environment.config = "C:/gosa-client.conf" Environment.noargs = True self.env = Environment.getInstance() self.env.log.info("GOsa client is starting up") env = self.env try: # Load plugins PluginRegistry(component='gosa_client.modules') amqp = PluginRegistry.getInstance("AMQPClientHandler") #TODO: # Check if we're a client # -> no: shutdown, client should be joined by administrator before # calling the client # Sleep and slice wait = 2 while True: # Threading doesn't seem to work well with python... for p in env.threads: # Bail out if we're active in the meanwhile if not env.active: break p.join(wait) # No break, go to main loop else: continue # Break, leave main loop break except Exception as detail: env.log.critical("unexpected error in mainLoop") env.log.exception(detail) env.log.debug(traceback.format_exc()) finally: pythoncom.CoUninitialize() # Signalize main thread to shut down win32api.Sleep(500) # Pull down system amqp = PluginRegistry.getInstance("AMQPClientHandler") amqp_service = PluginRegistry.getInstance("AMQPClientService") # Tell others that we're away now e = EventMaker() goodbye = e.Event(e.ClientLeave(e.Id(amqp_service.id))) amqp.sendEvent(goodbye) # Shutdown plugins PluginRegistry.shutdown() # Write another event log record. servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STOPPED, (self._svc_name_, '' ))