def start_service(self, service, service_address=None): if service == self.ICS_SERVICE: from rcmp_inter_communication import RCMPInterCommunicationServer, RCMPPacketHandler self._logger.info("Running RCM platform node '%s' on %s:%d" % (self.pni[self.PNI_NAME], service_address[0], service_address[1])) from rcmp_inter_communication import RCMPDispatcher from rcmp_ms import MServiceManager from rcmp_wd import WDogManager # pni keeps information from startup configuration msm = MServiceManager() self.dispatcher = RCMPDispatcher(self.pni, msm, WDogManager(self.pni, msm, self.error_event)) self.rcm_services[self.ICS_SERVICE] = RCMPInterCommunicationServer(service_address, RCMPPacketHandler, self.dispatcher) self.ics_service_runner = threading.Thread(name=self.ICS_SERVICE, target=self.rcm_services[self.ICS_SERVICE].serve_forever) # the parent process can't die until the thread non_daemon dies self.ics_service_runner.start() self._logger.info("Internal communication server started") elif service == self.EC_SERVICE: # the import of this object must be in run() or after because it imports # twisted that pre-opens some file descriptors and socket: if you import # here the open of the ContextDaemon of python-daemon is already done and # that component doesn't close the descriptors pre-opened by twisted from rcmp_ext_connector import RCMPExtConnector import multiprocessing self._logger.info("Running external connector on %s:%d" % (service_address[0], service_address[1])) ec = RCMPExtConnector() self.rcm_services[self.EC_SERVICE] = multiprocessing.Process(name=self.EC_SERVICE, target=ec.start, args=service_address) self._logger.info("External connector started") # the parent process can't die until the subprocess dies self.rcm_services[self.EC_SERVICE].start()
def add_watchdog(self, params): """Add a watchdog.""" try: self.wd_lock.acquire() if params and PNodeInstance.PI_ADDRESS_KEY in params and params[ PNodeInstance.PI_ADDRESS_KEY]: # we create the watchdog only if there isn't a watchdog monitoring the same address if params[PNodeInstance.PI_ADDRESS_KEY] not in self.wd: # we create a dispatcher to use internally in the watchdog dispatcher = RCMPDispatcher(self.pni, self.msm, self) st_e = threading.Event() self.wd[params[PNodeInstance.PI_ADDRESS_KEY]] = \ {WatchDog.WD_I_KEY: WatchDog(self.pni, dispatcher, st_e, self.pni_error_event, params[PNodeInstance.PI_NAME_KEY] if PNodeInstance.PI_NAME_KEY in params else None, params[PNodeInstance.PI_ADDRESS_KEY]), WatchDog.WD_STOP_EVENT_KEY: st_e} self._logger.debug("------ params ------") self._logger.debug(params) self._logger.debug("------ wd ------") self._logger.debug(self.wd) self._logger.debug("---------------") finally: self.wd_lock.release()