From 2379271c13e3d0f5430a498a86cdcbfff07120b3 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 12 Aug 2022 10:49:45 -0400 Subject: [PATCH] Island: Call _configure_gevent_ex_handling from _start_island_server --- monkey/monkey_island/cc/server_setup.py | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/monkey/monkey_island/cc/server_setup.py b/monkey/monkey_island/cc/server_setup.py index 2139e32d3..c3e56a477 100644 --- a/monkey/monkey_island/cc/server_setup.py +++ b/monkey/monkey_island/cc/server_setup.py @@ -51,10 +51,8 @@ def run_monkey_island(): _configure_logging(config_options) container = _initialize_di_container(config_options.data_dir) - _initialize_mongodb_connection(config_options.start_mongodb, config_options.data_dir) - _configure_gevent_exception_handling(config_options.data_dir) _start_island_server(island_args.setup_only, config_options, container) @@ -122,21 +120,11 @@ def _connect_to_mongodb(mongo_db_process: MongoDbProcess): sys.exit(1) -def _configure_gevent_exception_handling(data_dir): - hub = gevent.hub.get_hub() - - gevent_exception_log = open(data_dir / GEVENT_EXCEPTION_LOG, "w+", buffering=1) - atexit.register(gevent_exception_log.close) - - # Send gevent's exception output to a log file. - # https://www.gevent.org/api/gevent.hub.html#gevent.hub.Hub.exception_stream - hub.exception_stream = gevent_exception_log - hub.handle_error = GeventHubErrorHandler(hub, logger) - - def _start_island_server( should_setup_only: bool, config_options: IslandConfigOptions, container: DIContainer ): + _configure_gevent_exception_handling(config_options.data_dir) + app = init_app(mongo_setup.MONGO_URL, container) if should_setup_only: @@ -161,6 +149,18 @@ def _start_island_server( http_server.serve_forever() +def _configure_gevent_exception_handling(data_dir): + hub = gevent.hub.get_hub() + + gevent_exception_log = open(data_dir / GEVENT_EXCEPTION_LOG, "w+", buffering=1) + atexit.register(gevent_exception_log.close) + + # Send gevent's exception output to a log file. + # https://www.gevent.org/api/gevent.hub.html#gevent.hub.Hub.exception_stream + hub.exception_stream = gevent_exception_log + hub.handle_error = GeventHubErrorHandler(hub, logger) + + def _get_wsgi_server_logger() -> logging.Logger: wsgi_server_logger = logger.getChild("wsgi") wsgi_server_logger.addFilter(PyWSGILoggingFilter())