From 61cb14d6287ef1eddb2ea8205b5b65c417d4b134 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 12 Aug 2022 10:47:23 -0400 Subject: [PATCH] Island: Wrap mongo start in _initialize_mongodb_connection() --- monkey/monkey_island/cc/server_setup.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/monkey/monkey_island/cc/server_setup.py b/monkey/monkey_island/cc/server_setup.py index 418074557..2139e32d3 100644 --- a/monkey/monkey_island/cc/server_setup.py +++ b/monkey/monkey_island/cc/server_setup.py @@ -52,11 +52,7 @@ def run_monkey_island(): _configure_logging(config_options) container = _initialize_di_container(config_options.data_dir) - mongo_db_process = None - if config_options.start_mongodb: - mongo_db_process = _start_mongodb(config_options.data_dir) - - _connect_to_mongodb(mongo_db_process) + _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) @@ -95,6 +91,14 @@ def _initialize_di_container(data_dir: Path) -> DIContainer: return initialize_services(data_dir) +def _initialize_mongodb_connection(start_mongodb: bool, data_dir: Path): + mongo_db_process = None + if start_mongodb: + mongo_db_process = _start_mongodb(data_dir) + + _connect_to_mongodb(mongo_db_process) + + def _start_mongodb(data_dir: Path) -> MongoDbProcess: mongo_db_process = mongo_setup.start_mongodb(data_dir) mongo_setup.register_mongo_shutdown_callback(mongo_db_process)