systemd/start-eddn-service: Now replacing scripts/run-from-source.sh

* Removed scripts/run-from-source.sh as it's now redundant.
* Added `--background` optional argument, only for when using
  `--from-source` to start-eddn-service.  The script will leave the
  service in the foreground, no output redirection, without it.

  It tells you the PID of the process when it's backgrounded, as well as
  placing it in the appropriate .pid file.
This commit is contained in:
Athanasius
2021-07-06 11:17:52 +00:00
parent e049e2971b
commit 0e3ef098ab
3 changed files with 32 additions and 45 deletions

View File

@@ -397,8 +397,17 @@ You have some choices for how to run the application components:
## Running scripts from source
If you are just testing out code changes then you can choose to run
this application directly from the source using the provided script in
`scripts/run-from-source.sh`. This assumes the `dev` environment.
this application directly from the source using the script
`systemd/start-eddn-service`. You'll need to run it as, e.g.
systemd/start-eddn-service dev gateway --from-source
When using `--from-source` you can also supply a `--background` argument to
put the process into the background with a `.pid` file written in the logs
directory.
Check the `systemd/eddn_<environment>_config` files for the location of
the logs directory.
## Running from installation
Otherwise you will want to utilise the `setup.py` file to build and

View File

@@ -1,38 +0,0 @@
#!/bin/bash -x
BASEPATH="${HOME}/dev"
LOGPATH="${BASEPATH}/logs"
PYTHON="python2.7"
cd "${BASEPATH}" || exit 1
mkdir -p ${LOGPATH} || exit 2
cd EDDN.git/src/eddn || exit 4
for d in Relay Monitor Gateway ;
do
echo "$d"
PID_FILE="${LOGPATH}/${d}.pid"
if ps "$(cat ${PID_FILE})" >/dev/null 2>&1;
then
echo "$d: Already running as $(cat ${PID_FILE})"
continue
fi
CONFIG_FILE="${HOME}/.local/share/eddn/dev/config.json"
if [ -f "${CONFIG_FILE}" ];
then
CONFIG="--config ${CONFIG_FILE}"
else
echo "WARNING: No override settings found, you'll be using defaults"
echo "WARNING: Did you forget to make ${CONFIG_FILE} ?"
echo " Continuing anyway..."
CONFIG=""
fi
${PYTHON} -m eddn.${d} \
${CONFIG} \
> ${LOGPATH}/$d.log \
2>&1 &
echo $! > "${LOGPATH}/${d}.pid"
#sleep 1
done
# vim: textwidth=0 wrapmargin=0 tabstop=2 shiftwidth=2 softtabstop=2 smartindent smarttab

View File

@@ -8,7 +8,7 @@ EXIT_SERVICE_BIN_MISSING=2
EXIT_CL_ARGS=3
usage() {
echo "Usage: $(basename $0) ( live | beta | dev ) ( gateway | monitor | relay ) [ --from-source ]"
echo "Usage: $(basename $0) ( live | beta | dev ) ( gateway | monitor | relay ) [ --from-source [ --background ] ]"
}
if [ -z "${1}" ];
@@ -36,6 +36,15 @@ then
exit ${EXIT_CL_ARGS}
fi
FROM_SOURCE="1"
if [ ! -z "${4}" ];
then
if [ "${4}" != "--background" ];
then
usage
echo "Un-recognised argument: ${4}"
fi
BACKGROUND=1
fi
fi
EXEC_PATH=$(dirname $0)
@@ -77,10 +86,17 @@ else
#echo ${SERVICE}
SERVICE_CAMEL=$(echo ${SERVICE} | sed -s 's/^\(.\)/\u\1/;')
#echo ${SERVICE_CAMEL}
${PYTHON_VENV}/bin/python ${SERVICE_CAMEL}.py --config "${CONFIG_OVERRIDE}" >> "${LOG_DIR}/${SERVICE}.log" 2>&1 &
PID=$!
echo ${PID} > "${LOG_DIR}/${SERVICE}.pid"
echo "${SERVICE_CAMEL}.py started with PID: ${PID}"
if [ -z "${BACKGROUND}" ];
then
echo "Starting ${SERVICE_CAMEL} in foreground..."
${PYTHON_VENV}/bin/python ${SERVICE_CAMEL}.py --config "${CONFIG_OVERRIDE}"
else
echo "Starting ${SERVICE_CAMEL} in background..."
${PYTHON_VENV}/bin/python ${SERVICE_CAMEL}.py --config "${CONFIG_OVERRIDE}" >> "${LOG_DIR}/${SERVICE}.log" 2>&1 &
PID=$!
echo ${PID} > "${LOG_DIR}/${SERVICE}.pid"
echo "${SERVICE_CAMEL}.py started with PID: ${PID}"
fi
fi