mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-03-04 00:01:36 +01:00
Fix infinite restart loop: break on clean exit, cap crashes at 10
Co-authored-by: alexbelgium <44178713+alexbelgium@users.noreply.github.com>
This commit is contained in:
@@ -201,10 +201,20 @@ if $PID1; then
|
||||
chmod +x "$runfile"
|
||||
(
|
||||
restart_count=0
|
||||
max_restarts=10
|
||||
while true; do
|
||||
"$runfile" || true
|
||||
"$runfile"
|
||||
rc=$?
|
||||
if [ "$rc" -eq 0 ]; then
|
||||
echo "$runfile exited cleanly (exit 0), not restarting."
|
||||
break
|
||||
fi
|
||||
restart_count=$((restart_count + 1))
|
||||
echo -e "\e[38;5;214m$(date) WARNING: $runfile exited, restarting (#${restart_count}) in 5s...\e[0m"
|
||||
if [ "$restart_count" -ge "$max_restarts" ]; then
|
||||
echo -e "\033[0;31mERROR: $runfile has crashed $restart_count times (last exit code: $rc), giving up.\033[0m"
|
||||
break
|
||||
fi
|
||||
echo -e "\e[38;5;214m$(date) WARNING: $runfile exited (code $rc), restarting (#${restart_count}/${max_restarts}) in 5s...\e[0m"
|
||||
sleep 5
|
||||
done
|
||||
) &
|
||||
|
||||
Reference in New Issue
Block a user