From 808e86df1a851ad37006db7ae5b4aaa2aecbb8b8 Mon Sep 17 00:00:00 2001 From: Shreya Date: Fri, 14 May 2021 17:08:55 +0530 Subject: [PATCH] Create data_dir before logger is set up --- monkey/monkey_island.py | 8 ++++++++ monkey/monkey_island/cc/main.py | 7 ------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/monkey/monkey_island.py b/monkey/monkey_island.py index 958a1f529..31fa26382 100644 --- a/monkey/monkey_island.py +++ b/monkey/monkey_island.py @@ -10,6 +10,12 @@ import os # noqa: E402 from monkey_island import config_loader # noqa: E402 from monkey_island.cc.server_utils.island_logger import setup_logging # noqa: E402 + +def create_data_dir(data_dir): + if not os.path.isdir(data_dir): + os.makedirs(data_dir, mode=0o700) + + if "__main__" == __name__: island_args = parse_cli_args() @@ -23,6 +29,8 @@ if "__main__" == __name__: config = config_loader.load_server_config_from_file(server_config_path) + create_data_dir(config["data_dir"]) + setup_logging(config["data_dir"], config["log_level"]) except OSError as ex: diff --git a/monkey/monkey_island/cc/main.py b/monkey/monkey_island/cc/main.py index 497323f8b..cf56144ed 100644 --- a/monkey/monkey_island/cc/main.py +++ b/monkey/monkey_island/cc/main.py @@ -41,8 +41,6 @@ def main( ): logger.info("Starting bootloader server") - create_data_dir(data_dir) - env_singleton.initialize_from_file(server_config_filename) initialize_encryptor(data_dir) initialize_services(data_dir) @@ -57,11 +55,6 @@ def main( bootloader_server_thread.join() -def create_data_dir(data_dir): - if not os.path.isdir(data_dir): - os.makedirs(data_dir, mode=0o700) - - def start_island_server(should_setup_only): mongo_url = os.environ.get("MONGO_URL", env_singleton.env.get_mongo_url()) wait_for_mongo_db_server(mongo_url)