浏览代码

restart and monitor

Daniel Gibbs 1 年之前
父节点
当前提交
227647c0cc
共有 3 个文件被更改,包括 36 次插入9 次删除
  1. 17 1
      lgsm/modules/command_monitor.sh
  2. 16 0
      lgsm/modules/command_restart.sh
  3. 3 8
      lgsm/modules/command_stop.sh

+ 17 - 1
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

+ 16 - 0
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

+ 3 - 8
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