build: select server and logger config at runtime in appimage

This commit is contained in:
Mike Salvatore 2021-02-11 07:27:56 -05:00
parent 64018eb373
commit 2d971d95fc
5 changed files with 58 additions and 6 deletions

View File

@ -94,7 +94,7 @@ clone_monkey_repo() {
fi
log_message "Cloning files from git"
branch=${2:-"develop"}
branch=${2:-"select-logger-config-at-runtime"}
git clone --single-branch --recurse-submodules -b "$branch" "${MONKEY_GIT_URL}" "${REPO_MONKEY_HOME}" 2>&1 || handle_error
chmod 774 -R "${MONKEY_HOME}"
@ -105,7 +105,12 @@ copy_monkey_island_to_appdir() {
cp $REPO_MONKEY_SRC/monkey_island.py $INSTALL_DIR
cp -r $REPO_MONKEY_SRC/common $INSTALL_DIR
cp -r $REPO_MONKEY_SRC/monkey_island $INSTALL_DIR
cp ./run.sh $INSTALL_DIR/monkey_island/linux/
cp ./run_appimage.sh $INSTALL_DIR/monkey_island/linux/
cp ./island_logger_config.json $INSTALL_DIR/
# TODO: This is a workaround that may be able to be removed after PR #848 is
# merged. See monkey_island/cc/environment_singleton.py for more information.
cp $INSTALL_DIR/monkey_island/cc/server_config.json.standard $INSTALL_DIR/monkey_island/cc/server_config.json
}
install_monkey_island_python_dependencies() {
@ -231,7 +236,7 @@ cp $REPO_MONKEY_SRC/monkey_island/cc/ui/src/images/monkey-icon.svg $APPDIR/usr/s
#cp ./monkey_island.desktop $APPDIR
log_message "Building AppImage"
appimage-builder --recipe monkey_island_builder.yml --skip-appimage
appimage-builder --recipe monkey_island_builder.yml
log_message "Deployment script finished."

View File

@ -0,0 +1,33 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"simple": {
"format": "%(asctime)s - %(filename)s:%(lineno)s - %(funcName)10s() - %(levelname)s - %(message)s"
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "simple",
"stream": "ext://sys.stdout"
},
"info_file_handler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "INFO",
"formatter": "simple",
"filename": "~/.monkey_island/info.log",
"maxBytes": 10485760,
"backupCount": 20,
"encoding": "utf8"
}
},
"root": {
"level": "DEBUG",
"handlers": [
"console",
"info_file_handler"
]
}
}

View File

@ -9,7 +9,7 @@ AppDir:
icon: monkey-icon
version: 1.10.0
exec: bin/bash
exec_args: "$APPDIR/usr/src/monkey_island/linux/run.sh $HOME/.monkey_island/db"
exec_args: "$APPDIR/usr/src/monkey_island/linux/run_appimage.sh"
apt:

View File

@ -1,5 +1,14 @@
#!/bin/bash
DOT_MONKEY=$HOME/.monkey_island/
configure_default_logging() {
if [ ! -f $DOT_MONKEY/island_logger_config.json ]; then
cp $APPDIR/usr/src/island_logger_config.json $DOT_MONKEY
fi
}
# Detecting command that calls python 3.7
python_cmd=""
if [[ $(python --version 2>&1) == *"Python 3.7"* ]]; then
@ -12,10 +21,13 @@ if [[ $(python3.7 --version 2>&1) == *"Python 3.7"* ]]; then
python_cmd="python3.7"
fi
DB_DIR=${1:-"./monkey_island/bin/mongodb/db"}
mkdir -p $DOT_MONKEY
DB_DIR=$DOT_MONKEY/db
mkdir -p $DB_DIR
configure_default_logging
cd $APPDIR/usr/src
./monkey_island/bin/mongodb/bin/mongod --dbpath $DB_DIR &
${python_cmd} ./monkey_island.py
${python_cmd} ./monkey_island.py --server-config $DOT_MONKEY/server_config.json --logger-config $DOT_MONKEY/island_logger_config.json

View File

@ -51,4 +51,6 @@ def initialize_from_file(file_path):
raise
# TODO: This is only needed so that unit tests pass. After PR #848 is merged, we may be
# able to remove this line.
initialize_from_file(DEFAULT_SERVER_CONFIG_PATH)