From 3443b8c5a2ce3a05927efe35df5ded45a65e7d29 Mon Sep 17 00:00:00 2001 From: kaboom <58372747+kaboombot@users.noreply.github.com> Date: Sat, 9 Apr 2022 14:37:18 +0300 Subject: [PATCH] Implement crash loop detector --- script/alivecheck.sh | 3 +++ script/server.sh | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/script/alivecheck.sh b/script/alivecheck.sh index 2132886..253a284 100755 --- a/script/alivecheck.sh +++ b/script/alivecheck.sh @@ -13,5 +13,8 @@ while true; do if [ "$(env printf '\xFE' | nc -w 15 0.0.0.0 25565 | wc -m)" -eq 0 ]; then pkill -9 java echo $(date) >> ~/kill.log + else + # Server is still running, reset the crash loop detector + rm ~/server/server_stops.log fi done diff --git a/script/server.sh b/script/server.sh index 5285d6c..f39340b 100755 --- a/script/server.sh +++ b/script/server.sh @@ -11,6 +11,16 @@ java -Xshare:dump cd ~/server/ while true; do + # Check if the server is stuck in a crash loop, and reset worlds if this is the case + # The alive checker resets server_stops.log if the server runs long enough + + stop_log_file=server_stops.log + + if [ -f "$stop_log_file" ] && [ "$(wc -l < $stop_log_file)" -gt 3 ]; then + rm -rf worlds/ plugins/FastAsyncWorldEdit/clipboard/ plugins/FastAsyncWorldEdit/history/ + rm "$stop_log_file" + fi + # Make certain files and folders read-only mkdir debug/ dumps/ plugins/update/ @@ -46,6 +56,7 @@ while true; do # Stop alive checker (will be started again on the next run) pkill -9 alivecheck.sh + echo $(date) >> "$stop_log_file" # Ensure we don't abuse the CPU in case of failure sleep 1