diff --git a/apps/startup-scripts/src/simple-restarter b/apps/startup-scripts/src/simple-restarter index 62aea7fbd..a158b38be 100755 --- a/apps/startup-scripts/src/simple-restarter +++ b/apps/startup-scripts/src/simple-restarter @@ -66,7 +66,7 @@ while true; do echo "$(basename "$BINARY") terminated after $DIFFERENCE seconds, restart count: $_restart_count" # Crash loop detection - if [ $DIFFERENCE -lt 10 ]; then + if [ "$DIFFERENCE" -lt 10 ]; then # Increment instant crash count if runtime is lower than 10 seconds ((_instant_crash_count++)) echo "Warning: Quick restart detected ($DIFFERENCE seconds) - instant crash count: $_instant_crash_count" @@ -76,11 +76,17 @@ while true; do fi # Prevent infinite crash loops - if [ $_instant_crash_count -gt 5 ]; then + if [ "$_instant_crash_count" -gt 5 ]; then echo "Error: $(basename "$BINARY") restarter exited. Infinite crash loop prevented (6 crashes in under 10 seconds each)" echo "Please check your system configuration and logs" exit 1 fi + + # Exit cleanly if shutdown was requested by command or SIGINT (exit code 0) + if [ "$_exit_code" -eq 0 ]; then + echo "$(basename "$BINARY") shutdown safely" + exit 0 + fi echo "$(basename "$BINARY") will restart in 3 seconds..." sleep 3