From bc1eac9d3992b88f33d2d7399eb7ac5c029a3c15 Mon Sep 17 00:00:00 2001 From: wiaam96 <142393189+wiaam96@users.noreply.github.com> Date: Mon, 9 Jun 2025 16:11:45 +0300 Subject: [PATCH] Fix Watchdog restarts (#319) * don't exit * fix restarting agent * fix watchdog restarts --- build_system/docker/entry.sh | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/build_system/docker/entry.sh b/build_system/docker/entry.sh index f698034..69f67da 100644 --- a/build_system/docker/entry.sh +++ b/build_system/docker/entry.sh @@ -98,25 +98,16 @@ if [ -f "$FILE" ]; then fi touch /etc/cp/watchdog/wd.startup +/etc/cp/watchdog/cp-nano-watchdog >/dev/null 2>&1 & +active_watchdog_pid=$! while true; do - if [ -z "$init" ]; then - init=true - /etc/cp/watchdog/cp-nano-watchdog >/dev/null 2>&1 & - sleep 5 - active_watchdog_pid=$(pgrep -f -x -o "/bin/(bash|sh) /etc/cp/watchdog/cp-nano-watchdog") - fi - - current_watchdog_pid=$(pgrep -f -x -o "/bin/(bash|sh) /etc/cp/watchdog/cp-nano-watchdog") - if [ ! -f /tmp/restart_watchdog ] && [ "$current_watchdog_pid" != "$active_watchdog_pid" ]; then - echo "Error: Watchdog exited abnormally" - exit 1 - elif [ -f /tmp/restart_watchdog ]; then + if [ -f /tmp/restart_watchdog ]; then rm -f /tmp/restart_watchdog - kill -9 "$(pgrep -f -x -o "/bin/(bash|sh) /etc/cp/watchdog/cp-nano-watchdog")" - /etc/cp/watchdog/cp-nano-watchdog >/dev/null 2>&1 & - sleep 5 - active_watchdog_pid=$(pgrep -f -x -o "/bin/(bash|sh) /etc/cp/watchdog/cp-nano-watchdog") + kill -9 ${active_watchdog_pid} + fi + if [ ! "$(ps -f | grep cp-nano-watchdog | grep ${active_watchdog_pid})" ]; then + /etc/cp/watchdog/cp-nano-watchdog >/dev/null 2>&1 & + active_watchdog_pid=$! fi - sleep 5 done