diff --git a/includes/server.sh b/includes/server.sh index fe373b6..5b2c148 100644 --- a/includes/server.sh +++ b/includes/server.sh @@ -26,6 +26,7 @@ function start_server() { function stop_server() { ew ">>> Stopping server..." + kill -SIGTERM "${PLAYER_DETECTION_PID}" if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then save_and_shutdown_server fi diff --git a/scripts/restart.sh b/scripts/restart.sh index c70142e..753b566 100644 --- a/scripts/restart.sh +++ b/scripts/restart.sh @@ -8,6 +8,7 @@ source /includes/server.sh source /includes/webhook.sh function schedule_restart() { + PLAYER_DETECTION_PID=$(/dev/null + kill -SIGTERM "${PLAYER_DETECTION_PID}" ew ">>> Server stopped gracefully" exit 143; fi diff --git a/scripts/servermanager.sh b/scripts/servermanager.sh index c8a3150..0139097 100755 --- a/scripts/servermanager.sh +++ b/scripts/servermanager.sh @@ -14,6 +14,11 @@ source /includes/security.sh source /includes/server.sh source /includes/webhook.sh +START_MAIN_PID= +PLAYER_DETECTION_PID= + + + # Handler for SIGTERM from docker-based stop events function term_handler() { stop_server @@ -43,14 +48,17 @@ do ei ">>> Starting server manager" e "> Started at: $current_date $current_time" start_main & + START_MAIN_PID="$!" if [[ -n $RCON_PLAYER_DETECTION ]] && [[ $RCON_PLAYER_DETECTION == "true" ]] && [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then player_detection_loop & + PLAYER_DETECTION_PID="$!" + echo $PLAYER_DETECTION_PID > PLAYER_DETECTION.PID + e "> Player detection thread started with pid ${PLAYER_DETECTION_PID}" fi - killpid="$!" - e "> Server main thread started with pid ${killpid}" - wait ${killpid} + e "> Server main thread started with pid ${START_MAIN_PID}" + wait ${START_MAIN_PID} if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then send_stop_notification