From 415f5bb17dc31166d94a1eaab5503d317ca20be5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 14 Jun 2021 15:22:58 +0100 Subject: [PATCH] systemd: Change to a single script for starting services * Pass the EDDN service to be started as $1. * eddn_config now defines a python venv activate script to use. * And this new central script uses that. --- contrib/systemd/eddn@.service | 2 +- contrib/systemd/eddn_config | 1 + contrib/systemd/start-eddn-gateway | 16 ------------- contrib/systemd/start-eddn-monitor | 16 ------------- contrib/systemd/start-eddn-relay | 16 ------------- contrib/systemd/start-eddn-service | 37 ++++++++++++++++++++++++++++++ 6 files changed, 39 insertions(+), 49 deletions(-) delete mode 100755 contrib/systemd/start-eddn-gateway delete mode 100755 contrib/systemd/start-eddn-monitor delete mode 100755 contrib/systemd/start-eddn-relay create mode 100755 contrib/systemd/start-eddn-service diff --git a/contrib/systemd/eddn@.service b/contrib/systemd/eddn@.service index 541516b..7779172 100644 --- a/contrib/systemd/eddn@.service +++ b/contrib/systemd/eddn@.service @@ -18,7 +18,7 @@ After=network.target Type=simple User=eddn Group=eddn -ExecStart=/home/eddn/.local/bin/start-%i +ExecStart=/home/eddn/.local/bin/start-eddn-service %i TimeoutStartSec=10s TimeoutStopSec=10s SyslogIdentifier=eddn@%i diff --git a/contrib/systemd/eddn_config b/contrib/systemd/eddn_config index 6fbe7d3..68368d1 100644 --- a/contrib/systemd/eddn_config +++ b/contrib/systemd/eddn_config @@ -1,2 +1,3 @@ CONFIG_OVERRIDE="${HOME}/.local/share/eddn/config.json" LOG_DIR="${HOME}/.var/log/eddn" +PYTHON_VENV_ACTIVATE="${HOME}/eddn/python2.7-venv/bin/activate" diff --git a/contrib/systemd/start-eddn-gateway b/contrib/systemd/start-eddn-gateway deleted file mode 100755 index 6c71da4..0000000 --- a/contrib/systemd/start-eddn-gateway +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -# vim: tabstop=2 shiftwidth=2 textwidth=0 wrapmargin=0 expandtab -# -# Start the EDDN Gateway, including redirecting output to a log file. - -EXEC_PATH=$(dirname $0) -#echo "EXEC_PATH: ${EXEC_PATH}" - -# Ensure we're in the correct place -cd ${EXEC_PATH} -#pwd - -# Bring in some common configuration -. ./eddn_config - -./eddn-gateway --config "${CONFIG_OVERRIDE}" >> "${LOG_DIR}/eddn-gateway.log" 2>&1 diff --git a/contrib/systemd/start-eddn-monitor b/contrib/systemd/start-eddn-monitor deleted file mode 100755 index 717e3e2..0000000 --- a/contrib/systemd/start-eddn-monitor +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -# vim: tabstop=2 shiftwidth=2 textwidth=0 wrapmargin=0 expandtab -# -# Start the EDDN Gateway, including redirecting output to a log file. - -EXEC_PATH=$(dirname $0) -#echo "EXEC_PATH: ${EXEC_PATH}" - -# Ensure we're in the correct place -cd ${EXEC_PATH} -#pwd - -# Bring in some common configuration -. ./eddn_config - -./eddn-monitor --config "${CONFIG_OVERRIDE}" >> "${LOG_DIR}/eddn-monitor.log" 2>&1 diff --git a/contrib/systemd/start-eddn-relay b/contrib/systemd/start-eddn-relay deleted file mode 100755 index cb5bd82..0000000 --- a/contrib/systemd/start-eddn-relay +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -# vim: tabstop=2 shiftwidth=2 textwidth=0 wrapmargin=0 expandtab -# -# Start the EDDN Gateway, including redirecting output to a log file. - -EXEC_PATH=$(dirname $0) -#echo "EXEC_PATH: ${EXEC_PATH}" - -# Ensure we're in the correct place -cd ${EXEC_PATH} -#pwd - -# Bring in some common configuration -. ./eddn_config - -./eddn-relay --config "${CONFIG_OVERRIDE}" >> "${LOG_DIR}/eddn-relay.log" 2>&1 diff --git a/contrib/systemd/start-eddn-service b/contrib/systemd/start-eddn-service new file mode 100755 index 0000000..64b66bd --- /dev/null +++ b/contrib/systemd/start-eddn-service @@ -0,0 +1,37 @@ +#!/bin/bash -x +# vim: tabstop=2 shiftwidth=2 textwidth=0 wrapmargin=0 expandtab +# +# Start an EDDN Service, including redirecting output to a log file. + +if [ -z "${1}" ]; +then + echo "No EDDN service specified. One of: ${SERVICE}, monitor, relay" + exit 3 +fi +SERVICE="${1}" + +EXEC_PATH=$(dirname $0) +#echo "EXEC_PATH: ${EXEC_PATH}" + +# Ensure we're in the correct place +cd ${EXEC_PATH} +#pwd + +# Bring in some common configuration +if [ ! -f eddn_config ]; +then + echo "eddn_config is missing from $(pwd)" + exit 1 +fi +. ./eddn_config + +# Use the python venv +. "${PYTHON_VENV_ACTIVATE}" + +if [ ! -f eddn-${SERVICE} ]; +then + echo "eddn-${SERVICE} is missing from $(pwd)" + exit 2 +fi + +./eddn-${SERVICE} --config "${CONFIG_OVERRIDE}" >> "${LOG_DIR}/eddn-${SERVICE}.log" 2>&1