From 227647c0cc1f4c152c55b87f96c3760e480fbaea Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sun, 16 Jun 2024 21:31:30 +0100 Subject: [PATCH] restart and monitor --- lgsm/modules/command_monitor.sh | 18 +++++++++++++++++- lgsm/modules/command_restart.sh | 16 ++++++++++++++++ lgsm/modules/command_stop.sh | 11 +++-------- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/lgsm/modules/command_monitor.sh b/lgsm/modules/command_monitor.sh index 911cf5201..e7677e58f 100644 --- a/lgsm/modules/command_monitor.sh +++ b/lgsm/modules/command_monitor.sh @@ -110,12 +110,28 @@ fn_monitor_check_stopping() { } fn_monitor_check_restart_request() { - if [ -f "${lockdir}/${selfname}-stop-request.lock" ]; then + if [ -f "${lockdir}/${selfname}-restart-request.lock" ]; then fn_print_dots "Checking restart: " fn_print_checking_eol fn_print_info "Checking restart: Restart requested: " fn_print_info_eol_nl fn_script_log_info "Checking restart: Restart requested" + if [ "${stoponlyifnoplayers}" == "on" ]; then + if [ "${querymode}" == "2" ] || [ "${querymode}" == "3" ]; then + for queryip in "${queryips[@]}"; do + query_gamedig.sh + if [ "${querystatus}" == "0" ]; then + if [ -n "${gdplayers}" ] && [ "${gdplayers}" -ne 0 ]; then + fn_print_info_nl "${gdplayers} players are on the server: restart postponed" + fn_script_log_info "${gdplayers} players are on the server: restart postponed" + echo "${gdplayers}" > "${lockdir:?}/${selfname}-player-numbers.lock" + date '+%s' > "${lockdir:?}/${selfname}-restart-request.lock" + core_exit.sh + fi + fi + done + fi + fi command_restart.sh core_exit.sh fi diff --git a/lgsm/modules/command_restart.sh b/lgsm/modules/command_restart.sh index ed60a5555..fd3e1c35d 100644 --- a/lgsm/modules/command_restart.sh +++ b/lgsm/modules/command_restart.sh @@ -11,6 +11,22 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" fn_firstcommand_set info_game.sh +if [ "${stoponlyifnoplayers}" == "on" ]; then + if [ "${querymode}" == "2" ] || [ "${querymode}" == "3" ]; then + for queryip in "${queryips[@]}"; do + query_gamedig.sh + if [ "${querystatus}" == "0" ]; then + if [ -n "${gdplayers}" ] && [ "${gdplayers}" -ne 0 ]; then + fn_print_info_nl "${gdplayers} players are on the server: restart postponed" + fn_script_log_info "${gdplayers} players are on the server: restart postponed" + echo "${gdplayers}" > "${lockdir:?}/${selfname}-player-numbers.lock" + date '+%s' > "${lockdir:?}/${selfname}-restart-request.lock" + core_exit.sh + fi + fi + done + fi +fi exitbypass=1 command_stop.sh command_start.sh diff --git a/lgsm/modules/command_stop.sh b/lgsm/modules/command_stop.sh index 1dace37c9..93b1f71d9 100644 --- a/lgsm/modules/command_stop.sh +++ b/lgsm/modules/command_stop.sh @@ -18,15 +18,10 @@ fn_stop_players_online() { query_gamedig.sh if [ "${querystatus}" == "0" ]; then if [ -n "${gdplayers}" ] && [ "${gdplayers}" -ne 0 ]; then - fn_print_info_nl "Server will not stop while ${gdplayers} players are on the server" - fn_script_log_info "Server will not stop while ${gdplayers} players are on the server" - date '+%s' > "${lockdir:?}/${selfname}-stop-request.lock" + fn_print_info_nl "${gdplayers} players are on the server: stop prevented" + fn_script_log_info "${gdplayers} players are on the server: stop prevented" + echo "${gdplayers}" > "${lockdir:?}/${selfname}-player-numbers.lock" core_exit.sh - else - if [ -f "${lockdir:?}/${selfname}-stop-request.lock" ]; then - rm -f "${lockdir:?}/${selfname}-stop-request.lock" - fi - break fi fi done