|
@@ -1,7 +1,7 @@
|
|
|
#!/bin/bash
|
|
#!/bin/bash
|
|
|
# LinuxGSM command_stop.sh module
|
|
# LinuxGSM command_stop.sh module
|
|
|
# Author: Daniel Gibbs
|
|
# Author: Daniel Gibbs
|
|
|
-# Contributors: http://linuxgsm.com/contrib
|
|
|
|
|
|
|
+# Contributors: https://linuxgsm.com/contrib
|
|
|
# Website: https://linuxgsm.com
|
|
# Website: https://linuxgsm.com
|
|
|
# Description: Stops the server.
|
|
# Description: Stops the server.
|
|
|
|
|
|
|
@@ -96,8 +96,8 @@ fn_stop_graceful_goldsrc() {
|
|
|
|
|
|
|
|
# telnet command for sdtd graceful shutdown.
|
|
# telnet command for sdtd graceful shutdown.
|
|
|
fn_stop_graceful_sdtd_telnet() {
|
|
fn_stop_graceful_sdtd_telnet() {
|
|
|
- if [ -z "${telnetpass}" ] || [ "${telnetpass}" == "NOT SET" ]; then
|
|
|
|
|
- sdtd_telnet_shutdown=$(expect -c '
|
|
|
|
|
|
|
+ if [ -z "${telnetpassword}" ] || [ "${telnetpassword}" == "NOT SET" ]; then
|
|
|
|
|
+ sdtdtelnetshutdown=$(expect -c '
|
|
|
proc abort {} {
|
|
proc abort {} {
|
|
|
puts "Timeout or EOF\n"
|
|
puts "Timeout or EOF\n"
|
|
|
exit 1
|
|
exit 1
|
|
@@ -111,14 +111,14 @@ fn_stop_graceful_sdtd_telnet() {
|
|
|
puts "Completed.\n"
|
|
puts "Completed.\n"
|
|
|
')
|
|
')
|
|
|
else
|
|
else
|
|
|
- sdtd_telnet_shutdown=$(expect -c '
|
|
|
|
|
|
|
+ sdtdtelnetshutdown=$(expect -c '
|
|
|
proc abort {} {
|
|
proc abort {} {
|
|
|
puts "Timeout or EOF\n"
|
|
puts "Timeout or EOF\n"
|
|
|
exit 1
|
|
exit 1
|
|
|
}
|
|
}
|
|
|
spawn telnet '"${telnetip}"' '"${telnetport}"'
|
|
spawn telnet '"${telnetip}"' '"${telnetport}"'
|
|
|
expect {
|
|
expect {
|
|
|
- "password:" { send "'"${telnetpass}"'\r" }
|
|
|
|
|
|
|
+ "password:" { send "'"${telnetpassword}"'\r" }
|
|
|
default abort
|
|
default abort
|
|
|
}
|
|
}
|
|
|
expect {
|
|
expect {
|
|
@@ -143,8 +143,8 @@ fn_stop_graceful_sdtd() {
|
|
|
fn_print_dots "Graceful: telnet: ${telnetip}:${telnetport}"
|
|
fn_print_dots "Graceful: telnet: ${telnetip}:${telnetport}"
|
|
|
fn_script_log_info "Graceful: telnet: ${telnetip}:${telnetport}"
|
|
fn_script_log_info "Graceful: telnet: ${telnetip}:${telnetport}"
|
|
|
fn_stop_graceful_sdtd_telnet
|
|
fn_stop_graceful_sdtd_telnet
|
|
|
- completed=$(echo -en "\n ${sdtd_telnet_shutdown}" | grep "Completed.")
|
|
|
|
|
- refused=$(echo -en "\n ${sdtd_telnet_shutdown}" | grep "Timeout or EOF")
|
|
|
|
|
|
|
+ completed=$(echo -en "\n ${sdtdtelnetshutdown}" | grep "Completed.")
|
|
|
|
|
+ refused=$(echo -en "\n ${sdtdtelnetshutdown}" | grep "Timeout or EOF")
|
|
|
if [ "${refused}" ]; then
|
|
if [ "${refused}" ]; then
|
|
|
fn_print_error "Graceful: telnet: ${telnetip}:${telnetport} : "
|
|
fn_print_error "Graceful: telnet: ${telnetip}:${telnetport} : "
|
|
|
fn_print_fail_eol_nl
|
|
fn_print_fail_eol_nl
|
|
@@ -159,7 +159,7 @@ fn_stop_graceful_sdtd() {
|
|
|
if [ "${completed}" ]; then
|
|
if [ "${completed}" ]; then
|
|
|
for seconds in {1..30}; do
|
|
for seconds in {1..30}; do
|
|
|
fn_stop_graceful_sdtd_telnet
|
|
fn_stop_graceful_sdtd_telnet
|
|
|
- refused=$(echo -en "\n ${sdtd_telnet_shutdown}" | grep "Timeout or EOF")
|
|
|
|
|
|
|
+ refused=$(echo -en "\n ${sdtdtelnetshutdown}" | grep "Timeout or EOF")
|
|
|
if [ "${refused}" ]; then
|
|
if [ "${refused}" ]; then
|
|
|
fn_print_ok "Graceful: telnet: ${telnetip}:${telnetport} : "
|
|
fn_print_ok "Graceful: telnet: ${telnetip}:${telnetport} : "
|
|
|
fn_print_ok_eol_nl
|
|
fn_print_ok_eol_nl
|
|
@@ -185,7 +185,7 @@ fn_stop_graceful_sdtd() {
|
|
|
fi
|
|
fi
|
|
|
echo -en "\n" | tee -a "${lgsmlog}"
|
|
echo -en "\n" | tee -a "${lgsmlog}"
|
|
|
echo -en "Telnet output:" | tee -a "${lgsmlog}"
|
|
echo -en "Telnet output:" | tee -a "${lgsmlog}"
|
|
|
- echo -en "\n ${sdtd_telnet_shutdown}" | tee -a "${lgsmlog}"
|
|
|
|
|
|
|
+ echo -en "\n ${sdtdtelnetshutdown}" | tee -a "${lgsmlog}"
|
|
|
echo -en "\n\n" | tee -a "${lgsmlog}"
|
|
echo -en "\n\n" | tee -a "${lgsmlog}"
|
|
|
fi
|
|
fi
|
|
|
else
|
|
else
|
|
@@ -195,6 +195,95 @@ fn_stop_graceful_sdtd() {
|
|
|
fi
|
|
fi
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+# Attempts graceful shutdown of Soulmask using telnet.
|
|
|
|
|
+fn_stop_graceful_sm() {
|
|
|
|
|
+ fn_print_dots "Graceful: telnet"
|
|
|
|
|
+ fn_script_log_info "Graceful: telnet"
|
|
|
|
|
+ if [ "${telnetenabled}" == "false" ]; then
|
|
|
|
|
+ fn_print_info_nl "Graceful: telnet: DISABLED: Enable in ${servercfg}"
|
|
|
|
|
+ elif [ "$(command -v expect 2> /dev/null)" ]; then
|
|
|
|
|
+ # Tries to shutdown with both localhost and server IP.
|
|
|
|
|
+ for telnetip in 127.0.0.1 ${ip}; do
|
|
|
|
|
+ fn_print_dots "Graceful: telnet: ${telnetip}:${telnetport}"
|
|
|
|
|
+ fn_script_log_info "Graceful: telnet: ${telnetip}:${telnetport}"
|
|
|
|
|
+ fn_stop_graceful_sm_telnet
|
|
|
|
|
+ completed=$(echo -en "\n ${smtelnetshutdown}" | grep "Completed.")
|
|
|
|
|
+ refused=$(echo -en "\n ${smtelnetshutdown}" | grep "Timeout or EOF")
|
|
|
|
|
+ if [ "${refused}" ]; then
|
|
|
|
|
+ fn_print_error "Graceful: telnet: ${telnetip}:${telnetport} : "
|
|
|
|
|
+ fn_print_fail_eol_nl
|
|
|
|
|
+ fn_script_log_error "Graceful: telnet: ${telnetip}:${telnetport} : FAIL"
|
|
|
|
|
+ elif [ "${completed}" ]; then
|
|
|
|
|
+ break
|
|
|
|
|
+ fi
|
|
|
|
|
+ done
|
|
|
|
|
+
|
|
|
|
|
+ # If telnet shutdown was successful will use telnet again to check
|
|
|
|
|
+ # the connection has closed, confirming that the tmux session can now be killed.
|
|
|
|
|
+ if [ "${completed}" ]; then
|
|
|
|
|
+ for seconds in {1..30}; do
|
|
|
|
|
+ fn_stop_graceful_sm_telnet
|
|
|
|
|
+ refused=$(echo -en "\n ${smtelnetshutdown}" | grep "Timeout or EOF")
|
|
|
|
|
+ if [ "${refused}" ]; then
|
|
|
|
|
+ fn_print_ok "Graceful: telnet: ${telnetip}:${telnetport} : "
|
|
|
|
|
+ fn_print_ok_eol_nl
|
|
|
|
|
+ fn_script_log_pass "Graceful: telnet: ${telnetip}:${telnetport} : ${seconds} seconds"
|
|
|
|
|
+ if [ "${statusalert}" == "on" ] && [ "${firstcommandname}" == "STOP" ]; then
|
|
|
|
|
+ alert="stopped"
|
|
|
|
|
+ alert.sh
|
|
|
|
|
+ fi
|
|
|
|
|
+ break
|
|
|
|
|
+ fi
|
|
|
|
|
+ fn_sleep_time_1
|
|
|
|
|
+ fn_print_dots "Graceful: telnet: ${seconds}"
|
|
|
|
|
+ done
|
|
|
|
|
+ # If telnet shutdown fails, show it and stop
|
|
|
|
|
+ else
|
|
|
|
|
+ if [ "${refused}" ]; then
|
|
|
|
|
+ fn_print_error "Graceful: telnet: "
|
|
|
|
|
+ fn_print_fail_eol_nl
|
|
|
|
|
+ fn_script_log_error "Graceful: telnet: ${telnetip}:${telnetport} : FAIL"
|
|
|
|
|
+ else
|
|
|
|
|
+ fn_print_error_nl "Graceful: telnet: Unknown error"
|
|
|
|
|
+ fn_script_log_error "Graceful: telnet: Unknown error"
|
|
|
|
|
+ fi
|
|
|
|
|
+ echo -en "\n" | tee -a "${lgsmlog}"
|
|
|
|
|
+ echo -en "Telnet output:" | tee -a "${lgsmlog}"
|
|
|
|
|
+ echo -en "\n ${smtelnetshutdown}" | tee -a "${lgsmlog}"
|
|
|
|
|
+ echo -en "\n\n" | tee -a "${lgsmlog}"
|
|
|
|
|
+ fi
|
|
|
|
|
+ else
|
|
|
|
|
+ fn_print_warn "Graceful: telnet: expect not installed: "
|
|
|
|
|
+ fn_print_fail_eol_nl
|
|
|
|
|
+ fn_script_log_warn "Graceful: telnet: expect not installed: FAIL"
|
|
|
|
|
+ fi
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+# telnet command for soulmask graceful shutdown.
|
|
|
|
|
+fn_stop_graceful_sm_telnet() {
|
|
|
|
|
+ smtelnetshutdown=$(expect -c '
|
|
|
|
|
+ proc abort {} {
|
|
|
|
|
+ puts "Timeout or EOF\n"
|
|
|
|
|
+ exit 1
|
|
|
|
|
+ }
|
|
|
|
|
+ spawn telnet '"${telnetip}"' '"${telnetport}"'
|
|
|
|
|
+ expect {
|
|
|
|
|
+ "Hello:" { send "saveworld 1\r" }
|
|
|
|
|
+ default abort
|
|
|
|
|
+ }
|
|
|
|
|
+ expect {
|
|
|
|
|
+ "the world is saved." { send "quit 1\r" }
|
|
|
|
|
+ default abort
|
|
|
|
|
+ }
|
|
|
|
|
+ expect {
|
|
|
|
|
+ "World is closing..." {}
|
|
|
|
|
+ default abort
|
|
|
|
|
+ }
|
|
|
|
|
+ expect { eof }
|
|
|
|
|
+ puts "Completed.\n"
|
|
|
|
|
+ ')
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
# Attempts graceful shutdown by sending /save /stop.
|
|
# Attempts graceful shutdown by sending /save /stop.
|
|
|
fn_stop_graceful_avorion() {
|
|
fn_stop_graceful_avorion() {
|
|
|
fn_print_dots "Graceful: /save /stop"
|
|
fn_print_dots "Graceful: /save /stop"
|
|
@@ -253,6 +342,8 @@ fn_stop_graceful_select() {
|
|
|
fn_stop_graceful_cmd "end" 30
|
|
fn_stop_graceful_cmd "end" 30
|
|
|
elif [ "${stopmode}" == "12" ]; then
|
|
elif [ "${stopmode}" == "12" ]; then
|
|
|
fn_stop_graceful_cmd "shutdown" 30
|
|
fn_stop_graceful_cmd "shutdown" 30
|
|
|
|
|
+ elif [ "${stopmode}" == "13" ]; then
|
|
|
|
|
+ fn_stop_graceful_sm
|
|
|
fi
|
|
fi
|
|
|
}
|
|
}
|
|
|
|
|
|