From 359d346c33199c258cf1ae8f6ace3f55029636fa Mon Sep 17 00:00:00 2001 From: paspo Date: Mon, 14 Oct 2024 17:27:44 +0200 Subject: [PATCH] exit if lockfile present --- btrbk-cron | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/btrbk-cron b/btrbk-cron index c96fab6..4d7c865 100755 --- a/btrbk-cron +++ b/btrbk-cron @@ -1,6 +1,7 @@ #!/bin/bash CONF=/etc/btrbk/btrbk-cron.conf +LOCKFILE=/run/btrbk/btrbk.lock LOGFILE=$(mktemp) trap 'rm -f -- "${LOGFILE}"' EXIT @@ -29,6 +30,15 @@ else echo "Info: Healthchecks disabled" fi +if [[ -f "${LOCKFILE}" ]] ; then + echo "Another instance is still running" | tee -a "${LOGFILE}" + if [[ "${HEALTHCHECK_ENABLE}" = "true" ]] ; then + curl "${CURLOPTS[@]}" --data-binary "@${LOGFILE}" "${HEALTHCHECK_URL}/log" + fi + rm -f -- "${LOGFILE}" + exit 0 +fi + HOST=$(grep -E '^[\ \t]*target[\ \t]+send-receive' /etc/btrbk/btrbk.conf) # TODO: support for dashes in hostname and IPv6 ("[2001:db8::7]") HOST=$(echo "${HOST}" | sed -r 's/.*ssh:\/\/([0-9\.a-zA-Z]+).*/\1/g' )