From be4bbb0c23339e682e079a029fd132ab9381dd4c Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Mon, 3 Jun 2024 10:29:56 +0200 Subject: [PATCH] Update jobrunner daemon again --- bash/jobrunner/daemon.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bash/jobrunner/daemon.sh b/bash/jobrunner/daemon.sh index f5b5c86b..92c1b30d 100755 --- a/bash/jobrunner/daemon.sh +++ b/bash/jobrunner/daemon.sh @@ -3,7 +3,7 @@ # Logging functions function log() { - echo "${*}" + [[ -z "${JOBRUNNER_DISABLEOUTPUT}" ]] && echo "${*}" echo "${*}" >> "/tmp/jobrunner/jobrunner.log" } function logcmd() { @@ -12,7 +12,7 @@ function logcmd() { } # Set default timeout -[[ -z "${JOBRUNNER_TIMEOUT}" ]] && export "JOBRUNNER_TIMEOUT=0.5s" +[[ -z "${JOBRUNNER_TIMEOUT}" ]] && export "JOBRUNNER_TIMEOUT=0.1s" # Create runtime directory if [ -a "/tmp/jobrunner/" ] && [ ! -d "/tmp/jobrunner/" ]; then @@ -20,7 +20,9 @@ if [ -a "/tmp/jobrunner/" ] && [ ! -d "/tmp/jobrunner/" ]; then else echo ":: Creating runtime directory" mkdir -p "/tmp/jobrunner/" - echo "" > /tmp/jobrunner/jobrunner.{cmd,log} + + echo -e "" > /tmp/jobrunner/jobrunner.log + rm -rf /tmp/jobrunner/jobrunner.cmd fi # Check for PID file @@ -46,7 +48,7 @@ while true; do fi if [ -f "/tmp/jobrunner/jobrunner.cmd" ]; then - log "Executing command" + log ":: Executing command" # Read command file JOBRUNNER_COMMAND="$(cat "/tmp/jobrunner/jobrunner.cmd")" @@ -54,13 +56,14 @@ while true; do # Check if contains exit action if [ "${JOBRUNNER_COMMAND}" == "EXIT" ]; then - log "Exiting, as requested" + log ":: Exiting, as requested" logcmd rm -rf "/tmp/jobrunner/" exit 0 fi # Execute command in subprocess - bash -c "${JOBRUNNER_COMMAND}" & + echo ":: Execute: ${JOBRUNNER_COMMAND}" &>> /tmp/jobrunner/jobrunner.log + ( ${JOBRUNNER_COMMAND} ) &>> /tmp/jobrunner/jobrunner.log & fi # Sleep specified amount