From 086493b5bffbbc3c8f84feb035e5d2471848fd17 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 1 Jul 2021 16:52:25 +0000 Subject: [PATCH] Make it possible to split dev and live installs * Have 'dev' and 'live' components to many paths and file names. * Have separate dev/live systemd start script configs. * Have the systemd start script take a dev/live second argument. * Try to ensure permissions on 'web' files by explicitly setting umask. --- contrib/systemd/eddn_config | 3 --- contrib/systemd/eddn_dev_config | 3 +++ contrib/systemd/eddn_live_config | 3 +++ contrib/systemd/start-eddn-service | 25 +++++++++++++++++++------ setup.py | 16 +++++++++++++--- 5 files changed, 38 insertions(+), 12 deletions(-) delete mode 100644 contrib/systemd/eddn_config create mode 100644 contrib/systemd/eddn_dev_config create mode 100644 contrib/systemd/eddn_live_config diff --git a/contrib/systemd/eddn_config b/contrib/systemd/eddn_config deleted file mode 100644 index 22d7121..0000000 --- a/contrib/systemd/eddn_config +++ /dev/null @@ -1,3 +0,0 @@ -CONFIG_OVERRIDE="${HOME}/.local/share/eddn/config.json" -LOG_DIR="${HOME}/.var/log/eddn" -PYTHON_VENV="${HOME}/eddn/python-venv" diff --git a/contrib/systemd/eddn_dev_config b/contrib/systemd/eddn_dev_config new file mode 100644 index 0000000..cdfdee2 --- /dev/null +++ b/contrib/systemd/eddn_dev_config @@ -0,0 +1,3 @@ +CONFIG_OVERRIDE="${HOME}/.local/share/eddn/dev/config.json" +LOG_DIR="${HOME}/dev/logs" +PYTHON_VENV="${HOME}/dev/python-venv" diff --git a/contrib/systemd/eddn_live_config b/contrib/systemd/eddn_live_config new file mode 100644 index 0000000..1ce0827 --- /dev/null +++ b/contrib/systemd/eddn_live_config @@ -0,0 +1,3 @@ +CONFIG_OVERRIDE="${HOME}/.local/share/eddn/live/config.json" +LOG_DIR="${HOME}/live/logs" +PYTHON_VENV="${HOME}/live/python-venv" diff --git a/contrib/systemd/start-eddn-service b/contrib/systemd/start-eddn-service index 38d8c7d..a252872 100755 --- a/contrib/systemd/start-eddn-service +++ b/contrib/systemd/start-eddn-service @@ -3,13 +3,26 @@ # # Start an EDDN Service, including redirecting output to a log file. +usage() { + echo "Usage: $(basename $0) [ gateway | monitor | relay ] [ dev | live ]" +} + if [ -z "${1}" ]; then - echo "No EDDN service specified. One of: ${SERVICE}, monitor, relay" + usage + echo "No EDDN service specified." exit 3 fi SERVICE="${1}" +if [ -z "${2}" ]; +then + usage + echo "No EDDN environment specified." + exit 3 +fi +EDDN_ENV="${2}" + EXEC_PATH=$(dirname $0) #echo "EXEC_PATH: ${EXEC_PATH}" @@ -18,20 +31,20 @@ cd ${EXEC_PATH} #pwd # Bring in some common configuration -if [ ! -f eddn_config ]; +if [ ! -f "eddn_${EDDN_ENV}_config" ]; then - echo "eddn_config is missing from $(pwd)" + echo "eddn_${EDDN_ENV}_config is missing from $(pwd)" exit 1 fi -. ./eddn_config +. "./eddn_${EDDN_ENV}_config" # Use the python venv . "${PYTHON_VENV}/bin/activate" -if [ ! -f "${PYTHON_VENV}/bin/${SERVICE}" ]; +if [ ! -f "${PYTHON_VENV}/bin/eddn-${SERVICE}" ]; then echo "${SERVICE} is missing from ${PYTHON_VENV}/bin" exit 2 fi -exec ${PYTHON_VENV}/bin/${SERVICE} --config "${CONFIG_OVERRIDE}" >> "${LOG_DIR}/${SERVICE}.log" 2>&1 +exec ${PYTHON_VENV}/bin/eddn-${SERVICE} --config "${CONFIG_OVERRIDE}" >> "${LOG_DIR}/${SERVICE}.log" 2>&1 diff --git a/setup.py b/setup.py index 8b01793..c651055 100644 --- a/setup.py +++ b/setup.py @@ -17,10 +17,11 @@ except EnvironmentError: print "unable to find version in %s" % (VERSIONFILE,) raise RuntimeError("if %s exists, it is required to be well-formed" % (VERSIONFILE,)) +EDDN_ENV="dev" # Location of start-eddn-service script and its config file START_SCRIPT_BIN='%s/.local/bin' % ( os.environ['HOME'] ) # Location of web files -SHARE_EDDN_FILES='%s/.local/share/eddn' % ( os.environ['HOME'] ) +SHARE_EDDN_FILES='%s/.local/share/eddn/%s' % ( os.environ['HOME'], EDDN_ENV ) setup( name='eddn', @@ -93,10 +94,18 @@ if not os.path.isdir(START_SCRIPT_BIN): exit(-1) os.chdir(old_cwd) -for f in ( 'contrib/systemd/start-eddn-service', 'contrib/systemd/eddn_config'): - shutil.copy(f, START_SCRIPT_BIN) + +shutil.copy( + 'contrib/systemd/eddn_%s_config' % ( EDDN_ENV), + '%s/eddn_%s_config' % ( START_SCRIPT_BIN, EDDN_ENV ) +) +shutil.copy( + 'contrib/systemd/start-eddn-service', + '%s/start-eddn-%s-service' % ( START_SCRIPT_BIN, EDDN_ENV ) +) # Ensure the latest monitor files are in place +old_umask = os.umask(022) print """ ****************************************************************************** Ensuring %s exists... @@ -155,3 +164,4 @@ software will actually work. See docs/Running-this-software.md for guidance. ****************************************************************************** """ % ( SHARE_EDDN_FILES ) +os.umask(old_umask)