def _execute_site_sync_bg( self, args: Tuple[RequestContext, SiteId, SiteConfiguration, SiteRequest, ], ) -> SiteResult: log.init_logging() # NOTE: We run in a subprocess! with args[0]: return _execute_site_sync(*args[1:])
def run(self): # Ensure this process is not detected as apache process by the apache init script daemon.set_procname("cmk-activate-changes") # Detach from parent (apache) -> Remain running when apache is restarted os.setsid() # Cleanup existing livestatus connections (may be opened later when needed) cmk.gui.sites.disconnect() # Cleanup resources of the apache for x in range(3, 256): try: os.close(x) except OSError as e: if e.errno == errno.EBADF: pass else: raise # Reinitialize logging targets log.init_logging() try: self._do_run() except: logger.exception()
def _perform_tests_for_site( self, site_id: SiteId, result_queue: "multiprocessing.Queue[Tuple[SiteId, str]]") -> None: self._logger.debug("[%s] Starting" % site_id) result = None try: # Would be better to clean all open fds that are not needed, but we don't # know the FDs of the result_queue pipe. Can we find it out somehow? # Cleanup resources of the apache # for x in range(3, 256): # try: # os.close(x) # except OSError, e: # if e.errno == errno.EBADF: # pass # else: # raise # Reinitialize logging targets log.init_logging() # NOTE: We run in a subprocess! if site_is_local(site_id): automation = AutomationCheckAnalyzeConfig() results_data = automation.execute(automation.get_request()) else: results_data = watolib.do_remote_automation( get_site_config(site_id), "check-analyze-config", [], timeout=request.request_timeout - 10, ) self._logger.debug("[%s] Finished" % site_id) result = { "state": 0, "response": results_data, } except Exception: self._logger.exception("[%s] Failed" % site_id) result = { "state": 1, "response": "Traceback:<br>%s" % (traceback.format_exc().replace("\n", "<br>\n")), } finally: result_queue.put((site_id, repr(result))) result_queue.close() result_queue.join_thread() result_queue.join()
def initialize_environment(self): # setup logging log.init_logging() self._logger = log.logger.getChild("background_process") self._log_path_hint = _("More information can be found in ~/var/log/web.log") # Disable html request timeout if html.in_context(): html.disable_request_timeout() # Close livestatus connections inherited from the parent process sites.disconnect() super(GUIBackgroundProcess, self).initialize_environment()
def initialize_environment(self): # setup logging log.init_logging() # NOTE: We run in a subprocess! self._logger = log.logger.getChild("background-job") self._log_path_hint = _( "More information can be found in ~/var/log/web.log") # Disable html request timeout if timeout_manager: timeout_manager.disable_timeout() # Close livestatus connections inherited from the parent process sites.disconnect() super().initialize_environment()
def _perform_tests_for_site(self, site_id, result_queue): self._logger.debug("[%s] Starting" % site_id) try: # Would be better to clean all open fds that are not needed, but we don't # know the FDs of the result_queue pipe. Can we find it out somehow? # Cleanup resources of the apache #for x in range(3, 256): # try: # os.close(x) # except OSError, e: # if e.errno == 9: # Bad file descriptor # pass # else: # raise # Reinitialize logging targets log.init_logging() if config.site_is_local(site_id): automation = AutomationCheckAnalyzeConfig() results_data = automation.execute(automation.get_request()) else: results_data = watolib.do_remote_automation( config.site(site_id), "check-analyze-config", []) self._logger.debug("[%s] Finished" % site_id) result = { "state": 0, "response": results_data, } except Exception: self._logger.exception("[%s] Failed" % site_id) result = { "state": 1, "response": "Traceback:<br>%s" % (traceback.format_exc().replace("\n", "<br>\n")), } finally: result_queue.put((site_id, repr(result))) result_queue.close() result_queue.join_thread() result_queue.join()
def _execute_site_sync_bg(self, args: Tuple[SiteId, SiteConfiguration, SiteRequest]) -> SiteResult: log.init_logging() # NOTE: We run in a subprocess! return _execute_site_sync(*args)