island: Remove the responsibility of choosing a log file from MongoDbProcess

This commit is contained in:
Mike Salvatore 2021-06-02 20:15:16 -04:00
parent 5f25debfd2
commit 44a3456c62
2 changed files with 6 additions and 6 deletions

View File

@ -1,5 +1,4 @@
import logging
import os
import subprocess
from monkey_island.cc.server_utils.consts import MONGO_EXECUTABLE_PATH
@ -7,18 +6,17 @@ from monkey_island.cc.server_utils.consts import MONGO_EXECUTABLE_PATH
logger = logging.getLogger(__name__)
DB_DIR_PARAM = "--dbpath"
MONGO_LOG_FILENAME = "mongodb.log"
TERMINATE_TIMEOUT = 10
class MongoDbProcess:
def __init__(self, db_dir: str, logging_dir: str):
def __init__(self, db_dir: str, log_file: str):
"""
@param db_dir: Path where a folder for database contents will be created
@param logging_dir: Path to a folder where mongodb logs will be created
@param log_file: Path to the file that will contain mongodb logs
"""
self._mongo_run_cmd = [MONGO_EXECUTABLE_PATH, DB_DIR_PARAM, db_dir]
self._log_file = os.path.join(logging_dir, MONGO_LOG_FILENAME)
self._log_file = log_file
self._process = None
def start(self):

View File

@ -11,6 +11,7 @@ from monkey_island.cc.setup.mongo.mongo_connector import MONGO_DB_HOST, MONGO_DB
from monkey_island.cc.setup.mongo.mongo_db_process import MongoDbProcess
DB_DIR_NAME = "db"
MONGO_LOG_FILENAME = "mongodb.log"
MONGO_URL = os.environ.get(
"MONKEY_MONGO_URL",
"mongodb://{0}:{1}/{2}".format(MONGO_DB_HOST, MONGO_DB_PORT, MONGO_DB_NAME),
@ -22,8 +23,9 @@ logger = logging.getLogger(__name__)
def start_mongodb(data_dir: str) -> MongoDbProcess:
db_dir = _create_db_dir(data_dir)
log_file = os.path.join(data_dir, MONGO_LOG_FILENAME)
mongo_db_process = MongoDbProcess(db_dir=db_dir, logging_dir=data_dir)
mongo_db_process = MongoDbProcess(db_dir=db_dir, log_file=log_file)
mongo_db_process.start()
return mongo_db_process