From 4b630cb72615e6a4f02cbaca7778fd0877abcba9 Mon Sep 17 00:00:00 2001 From: "Dylan T." Date: Fri, 15 Nov 2024 21:14:21 +0000 Subject: [PATCH] start.sh: print warnings on unusual exit codes from the server process (#6497) --- start.sh | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/start.sh b/start.sh index 4d4787114..8f458b4e6 100755 --- a/start.sh +++ b/start.sh @@ -44,6 +44,27 @@ fi LOOPS=0 +handle_exit_code() { + local exitcode=$1 + if [ "$exitcode" -eq 134 ] || [ "$exitcode" -eq 139 ]; then #SIGABRT/SIGSEGV + echo "" + echo "ERROR: The server process was killed due to a critical error (code $exitcode) which could indicate a problem with PHP." + echo "Updating your PHP binary is recommended." + echo "If this keeps happening, please open a bug report." + echo "" + elif [ "$exitcode" -eq 143 ]; then #SIGKILL, maybe user intervention + echo "" + echo "WARNING: Server was forcibly killed!" + echo "If you didn't kill the server manually, this probably means the server used too much memory and was killed by the system's OOM Killer." + echo "Please ensure your system has enough available RAM." + echo "" + elif [ "$exitcode" -ne 0 ] && [ "$exitcode" -ne 137 ]; then #normal exit / SIGTERM + echo "" + echo "WARNING: Server did not shut down correctly! (code $exitcode)" + echo "" + fi +} + set +e if [ "$DO_LOOP" == "yes" ]; then @@ -52,11 +73,15 @@ if [ "$DO_LOOP" == "yes" ]; then echo "Restarted $LOOPS times" fi "$PHP_BINARY" "$POCKETMINE_FILE" "$@" + handle_exit_code $? echo "To escape the loop, press CTRL+C now. Otherwise, wait 5 seconds for the server to restart." echo "" sleep 5 ((LOOPS++)) done else - exec "$PHP_BINARY" "$POCKETMINE_FILE" "$@" + "$PHP_BINARY" "$POCKETMINE_FILE" "$@" + exitcode=$? + handle_exit_code $exitcode + exit $exitcode fi