forked from p15670423/monkey
island: Remove the responsibility of choosing a log file from MongoDbProcess
This commit is contained in:
parent
5f25debfd2
commit
44a3456c62
|
@ -1,5 +1,4 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from monkey_island.cc.server_utils.consts import MONGO_EXECUTABLE_PATH
|
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__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
DB_DIR_PARAM = "--dbpath"
|
DB_DIR_PARAM = "--dbpath"
|
||||||
MONGO_LOG_FILENAME = "mongodb.log"
|
|
||||||
TERMINATE_TIMEOUT = 10
|
TERMINATE_TIMEOUT = 10
|
||||||
|
|
||||||
|
|
||||||
class MongoDbProcess:
|
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 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._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
|
self._process = None
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
|
|
@ -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
|
from monkey_island.cc.setup.mongo.mongo_db_process import MongoDbProcess
|
||||||
|
|
||||||
DB_DIR_NAME = "db"
|
DB_DIR_NAME = "db"
|
||||||
|
MONGO_LOG_FILENAME = "mongodb.log"
|
||||||
MONGO_URL = os.environ.get(
|
MONGO_URL = os.environ.get(
|
||||||
"MONKEY_MONGO_URL",
|
"MONKEY_MONGO_URL",
|
||||||
"mongodb://{0}:{1}/{2}".format(MONGO_DB_HOST, MONGO_DB_PORT, MONGO_DB_NAME),
|
"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:
|
def start_mongodb(data_dir: str) -> MongoDbProcess:
|
||||||
db_dir = _create_db_dir(data_dir)
|
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()
|
mongo_db_process.start()
|
||||||
|
|
||||||
return mongo_db_process
|
return mongo_db_process
|
||||||
|
|
Loading…
Reference in New Issue