Loading tools/edit_monitor/daemon_manager.py +3 −3 Original line number Diff line number Diff line Loading @@ -154,7 +154,7 @@ class DaemonManager: def stop(self): """Stops the daemon process and removes the pidfile.""" logging.debug("in daemon manager cleanup.") logging.info("in daemon manager cleanup.") try: if self.daemon_process: # The daemon process might already in termination process, Loading @@ -163,7 +163,7 @@ class DaemonManager: if self.daemon_process.is_alive(): self._terminate_process(self.daemon_process.pid) self._remove_pidfile() logging.debug("Successfully stopped daemon manager.") logging.info("Successfully stopped daemon manager.") except Exception as e: logging.exception("Failed to stop daemon manager with error %s", e) self._send_error_event_to_clearcut( Loading @@ -179,7 +179,7 @@ class DaemonManager: Stops the current daemon manager and reboots the entire process based on the binary file. Exits directly If the binary file no longer exists. """ logging.debug("Rebooting process based on binary %s.", self.binary_path) logging.info("Rebooting process based on binary %s.", self.binary_path) # Stop the current daemon manager first. self.stop() Loading tools/edit_monitor/main.py +13 −3 Original line number Diff line number Diff line Loading @@ -57,17 +57,27 @@ def create_arg_parser(): ), ) parser.add_argument( '--verbose', action='store_true', help=( 'Log verbose info in the log file for debugging purpose.' ), ) return parser def configure_logging(): def configure_logging(verbose=False): root_logging_dir = tempfile.mkdtemp(prefix='edit_monitor_') _, log_path = tempfile.mkstemp(dir=root_logging_dir, suffix='.log') log_fmt = '%(asctime)s %(filename)s:%(lineno)s:%(levelname)s: %(message)s' date_fmt = '%Y-%m-%d %H:%M:%S' log_level = logging.DEBUG if verbose else logging.INFO logging.basicConfig( filename=log_path, level=logging.DEBUG, format=log_fmt, datefmt=date_fmt filename=log_path, level=log_level, format=log_fmt, datefmt=date_fmt ) # Filter out logs from inotify_buff to prevent log pollution. logging.getLogger('watchdog.observers.inotify_buffer').addFilter( Loading @@ -82,6 +92,7 @@ def term_signal_handler(_signal_number, _frame): def main(argv: list[str]): args = create_arg_parser().parse_args(argv[1:]) configure_logging(args.verbose) if args.dry_run: logging.info('This is a dry run.') dm = daemon_manager.DaemonManager( Loading @@ -104,5 +115,4 @@ def main(argv: list[str]): if __name__ == '__main__': signal.signal(signal.SIGTERM, term_signal_handler) configure_logging() main(sys.argv) Loading
tools/edit_monitor/daemon_manager.py +3 −3 Original line number Diff line number Diff line Loading @@ -154,7 +154,7 @@ class DaemonManager: def stop(self): """Stops the daemon process and removes the pidfile.""" logging.debug("in daemon manager cleanup.") logging.info("in daemon manager cleanup.") try: if self.daemon_process: # The daemon process might already in termination process, Loading @@ -163,7 +163,7 @@ class DaemonManager: if self.daemon_process.is_alive(): self._terminate_process(self.daemon_process.pid) self._remove_pidfile() logging.debug("Successfully stopped daemon manager.") logging.info("Successfully stopped daemon manager.") except Exception as e: logging.exception("Failed to stop daemon manager with error %s", e) self._send_error_event_to_clearcut( Loading @@ -179,7 +179,7 @@ class DaemonManager: Stops the current daemon manager and reboots the entire process based on the binary file. Exits directly If the binary file no longer exists. """ logging.debug("Rebooting process based on binary %s.", self.binary_path) logging.info("Rebooting process based on binary %s.", self.binary_path) # Stop the current daemon manager first. self.stop() Loading
tools/edit_monitor/main.py +13 −3 Original line number Diff line number Diff line Loading @@ -57,17 +57,27 @@ def create_arg_parser(): ), ) parser.add_argument( '--verbose', action='store_true', help=( 'Log verbose info in the log file for debugging purpose.' ), ) return parser def configure_logging(): def configure_logging(verbose=False): root_logging_dir = tempfile.mkdtemp(prefix='edit_monitor_') _, log_path = tempfile.mkstemp(dir=root_logging_dir, suffix='.log') log_fmt = '%(asctime)s %(filename)s:%(lineno)s:%(levelname)s: %(message)s' date_fmt = '%Y-%m-%d %H:%M:%S' log_level = logging.DEBUG if verbose else logging.INFO logging.basicConfig( filename=log_path, level=logging.DEBUG, format=log_fmt, datefmt=date_fmt filename=log_path, level=log_level, format=log_fmt, datefmt=date_fmt ) # Filter out logs from inotify_buff to prevent log pollution. logging.getLogger('watchdog.observers.inotify_buffer').addFilter( Loading @@ -82,6 +92,7 @@ def term_signal_handler(_signal_number, _frame): def main(argv: list[str]): args = create_arg_parser().parse_args(argv[1:]) configure_logging(args.verbose) if args.dry_run: logging.info('This is a dry run.') dm = daemon_manager.DaemonManager( Loading @@ -104,5 +115,4 @@ def main(argv: list[str]): if __name__ == '__main__': signal.signal(signal.SIGTERM, term_signal_handler) configure_logging() main(sys.argv)