From 1c445a43b4f0fc8cbe67879e297492d0f67a5568 Mon Sep 17 00:00:00 2001 From: Dominik Dzienia Date: Mon, 9 Mar 2026 17:10:11 +0100 Subject: [PATCH] Refactor watchdog logic to implement host-based delay in watchdog_run function --- src/commandline.sh | 2 +- src/logic_watchdog.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/commandline.sh b/src/commandline.sh index 924cf94..66ae28a 100644 --- a/src/commandline.sh +++ b/src/commandline.sh @@ -200,6 +200,6 @@ parse_commandline_args() { if [ "$WATCHDOGMODE" = "true" ]; then startup_version startup_debug - watchdog_check + watchdog_run fi } diff --git a/src/logic_watchdog.sh b/src/logic_watchdog.sh index de36fe0..4e74be7 100644 --- a/src/logic_watchdog.sh +++ b/src/logic_watchdog.sh @@ -160,6 +160,15 @@ get_watchdog_status() { } +watchdog_run() { + local host_hash + host_hash=$(printf '%s' "$(hostname)" | md5sum | awk '{print $1}' | cut -c1-8 | xargs printf '%d' 16 16) + local offset=$(( host_hash % 300 )) + echo "Watchdog delay: sleeping ${offset}s (host-based offset)" + sleep "$offset" + watchdog_check +} + watchdog_check() { echo "---------------------------" echo " Nightscout Watchdog mode"