From d9be69d3a927e4078dc6ff7994c693609b6207d3 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sun, 11 Sep 2022 11:26:57 +0200 Subject: [PATCH] bundles/systemd-timers: don't auto-reset alerts --- .../systemd-timers/files/check_systemd_timer | 20 ++++++++----------- .../files/systemd-timer-monitored | 9 +++++++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/bundles/systemd-timers/files/check_systemd_timer b/bundles/systemd-timers/files/check_systemd_timer index c037641..8609cd4 100644 --- a/bundles/systemd-timers/files/check_systemd_timer +++ b/bundles/systemd-timers/files/check_systemd_timer @@ -8,17 +8,13 @@ fi if ! [[ -f "/var/lib/systemd-timer-monitored/$1" ]] then - echo "No status file found" - exit 3 -fi - -exitcode="$(cat "/var/lib/systemd-timer-monitored/$1")" - -echo "Last timer run exited $exitcode" - -if [[ $exitcode -ne 0 ]] -then - exit 2 -else + echo "Everything is fine" exit 0 fi + +date="$(date --date="@$(cat "/var/lib/systemd-timer-monitored/$1")" "+%F %T %z")" + +echo "Timer had an error during its run on $date" +echo +echo "Remove /var/lib/systemd-timer-monitored/$1 to clean this alert" +exit 2 diff --git a/bundles/systemd-timers/files/systemd-timer-monitored b/bundles/systemd-timers/files/systemd-timer-monitored index 8af40f8..d9a2482 100644 --- a/bundles/systemd-timers/files/systemd-timer-monitored +++ b/bundles/systemd-timers/files/systemd-timer-monitored @@ -3,8 +3,13 @@ timer="$1" shift -# Simple wrapper script that stores the exit code of a command into a file "$@" exitcode=$? -echo "$exitcode" > "/var/lib/systemd-timer-monitored/$timer" +if [[ $exitcode -ne 0 ]] +then + echo "$(date -u +%s)" > "/var/lib/systemd-timer-monitored/$timer" +fi + +# to make systemd aware of the error, too. +exit $exitcode