From 2adcac027b2a90266197383def9c7acb2a2e0e80 Mon Sep 17 00:00:00 2001 From: paspo Date: Tue, 15 Oct 2024 08:16:57 +0200 Subject: [PATCH] stale lockfile check --- btrbk-cron | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/btrbk-cron b/btrbk-cron index 9307545..5153781 100755 --- a/btrbk-cron +++ b/btrbk-cron @@ -31,13 +31,21 @@ else echo "Info: Healthchecks disabled" fi +# lockfile check 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" + # check if stale lockfile + if [[ $(pgrep -c btrbk || true) -eq 0 ]] ; then + echo "Removing stale lock file: ${LOCKFILE}" + rm "${LOCKFILE}" + else + # another instance is really running, we exit + 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 - rm -f -- "${LOGFILE}" - exit 0 fi HOST=$(grep -E '^[\ \t]*target[\ \t]+send-receive' /etc/btrbk/btrbk.conf)