Przeglądaj źródła

fix(rwserver): stop Rising World gracefully with shutdown (#5031)

Daniel Gibbs 5 dni temu
rodzic
commit
b42436ada3

+ 3 - 1
lgsm/config-default/config-lgsm/rwserver/_default.cfg

@@ -150,7 +150,9 @@ steammaster="false"
 # 9: GoldSrc
 # 9: GoldSrc
 # 10: Avorion
 # 10: Avorion
 # 11: end
 # 11: end
-stopmode="3"
+# 12: shutdown
+# 15: Rising World
+stopmode="15"
 
 
 ## Query mode
 ## Query mode
 # 1: session only
 # 1: session only

+ 2 - 1
lgsm/modules/command_send.sh

@@ -27,7 +27,8 @@ if [ "${status}" != "0" ]; then
 	echo ""
 	echo ""
 	fn_print_dots "Sending command to console: \"${commandtosend}\""
 	fn_print_dots "Sending command to console: \"${commandtosend}\""
 	fn_print_ok_nl "Sending command to console: \"${commandtosend}\""
 	fn_print_ok_nl "Sending command to console: \"${commandtosend}\""
-	TERM=screen tmux -L "${socketname}" send-keys -t "${sessionname}" "${commandtosend}" ENTER
+	TERM=screen tmux -L "${socketname}" send-keys -t "${sessionname}" -l "${commandtosend}"
+	TERM=screen tmux -L "${socketname}" send-keys -t "${sessionname}" ENTER
 	fn_script_log_pass "Command \"${commandtosend}\" sent to console"
 	fn_script_log_pass "Command \"${commandtosend}\" sent to console"
 else
 else
 	fn_print_error_nl "Unable to send command to console. Server not running"
 	fn_print_error_nl "Unable to send command to console. Server not running"

+ 36 - 0
lgsm/modules/command_stop.sh

@@ -523,6 +523,40 @@ fn_stop_graceful_rwr() {
 	fn_stop_graceful_ctrlc
 	fn_stop_graceful_ctrlc
 }
 }
 
 
+# Attempts graceful shutdown of Rising World using 'shutdown'.
+# Its console can miss input, so the command is sent again every 10 seconds until the server stops.
+fn_stop_graceful_rw() {
+	fn_print_dots "Graceful: sending \"shutdown\""
+	fn_script_log_info "Graceful: sending \"shutdown\""
+	for ((seconds = 1; seconds <= 120; seconds++)); do
+		if [ $((seconds % 10)) -eq 1 ]; then
+			TERM=screen tmux -L "${socketname}" send-keys -t "${sessionname}" ENTER > /dev/null 2>&1
+			sleep 1
+			TERM=screen tmux -L "${socketname}" send-keys -t "${sessionname}" -l "shutdown" > /dev/null 2>&1
+			TERM=screen tmux -L "${socketname}" send-keys -t "${sessionname}" ENTER > /dev/null 2>&1
+		fi
+		check_status.sh
+		if [ "${status}" == "0" ]; then
+			fn_print_ok "Graceful: sending \"shutdown\": ${seconds}"
+			fn_print_ok_eol_nl
+			fn_script_log_pass "Graceful: sending \"shutdown\": OK: ${seconds} seconds"
+			if [ "${statusalert}" == "on" ] && [ "${firstcommandname}" == "STOP" ]; then
+				alert="stopped"
+				alert.sh
+			fi
+			break
+		fi
+		fn_sleep_time_1
+		fn_print_dots "Graceful: sending \"shutdown\": ${seconds}"
+	done
+	check_status.sh
+	if [ "${status}" != "0" ]; then
+		fn_print_error "Graceful: sending \"shutdown\": "
+		fn_print_fail_eol_nl
+		fn_script_log_error "Graceful: sending \"shutdown\": FAIL"
+	fi
+}
+
 fn_stop_graceful_select() {
 fn_stop_graceful_select() {
 	if [ "${stopmode}" == "1" ]; then
 	if [ "${stopmode}" == "1" ]; then
 		fn_stop_tmux
 		fn_stop_tmux
@@ -552,6 +586,8 @@ fn_stop_graceful_select() {
 		fn_stop_graceful_sm
 		fn_stop_graceful_sm
 	elif [ "${stopmode}" == "14" ]; then
 	elif [ "${stopmode}" == "14" ]; then
 		fn_stop_graceful_rwr
 		fn_stop_graceful_rwr
+	elif [ "${stopmode}" == "15" ]; then
+		fn_stop_graceful_rw
 	fi
 	fi
 }
 }