From 4a1653ed5f7f510ee9dfdfe4b0b589185d823c9a Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 2 Jun 2021 19:22:26 -0400 Subject: [PATCH] island: Do not start bootloader server if --setup-only is passed --- monkey/monkey_island/cc/server_setup.py | 26 +++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/monkey/monkey_island/cc/server_setup.py b/monkey/monkey_island/cc/server_setup.py index ba0ed1411..692a945ff 100644 --- a/monkey/monkey_island/cc/server_setup.py +++ b/monkey/monkey_island/cc/server_setup.py @@ -50,9 +50,7 @@ def run_monkey_island(): connect_to_mongodb() - bootloader_server_thread = _start_bootloader_server(MONGO_URL) _start_island_server(island_args.setup_only, config_options) - bootloader_server_thread.join() def _configure_logging(config_options): @@ -67,16 +65,6 @@ def _initialize_global_resources(config_options: IslandConfigOptions, server_con initialize_services(config_options.data_dir) -def _start_bootloader_server(mongo_url) -> Thread: - bootloader_server_thread = Thread( - target=BootloaderHttpServer(mongo_url).serve_forever, daemon=True - ) - - bootloader_server_thread.start() - - return bootloader_server_thread - - def _start_island_server(should_setup_only, config_options: IslandConfigOptions): populate_exporter_list() app = init_app(MONGO_URL) @@ -90,6 +78,8 @@ def _start_island_server(should_setup_only, config_options: IslandConfigOptions) logger.warning("Setup only flag passed. Exiting.") return + bootloader_server_thread = _start_bootloader_server(MONGO_URL) + if env_singleton.env.is_debug(): app.run(host="0.0.0.0", debug=True, ssl_context=(crt_path, key_path)) else: @@ -102,6 +92,18 @@ def _start_island_server(should_setup_only, config_options: IslandConfigOptions) _log_init_info() http_server.serve_forever() + bootloader_server_thread.join() + + +def _start_bootloader_server(mongo_url) -> Thread: + bootloader_server_thread = Thread( + target=BootloaderHttpServer(mongo_url).serve_forever, daemon=True + ) + + bootloader_server_thread.start() + + return bootloader_server_thread + def _log_init_info(): logger.info("Monkey Island Server is running!")