Browse Source

Getting sdtd graceful working better

pull/743/head
Daniel Gibbs 9 years ago
parent
commit
77c5692bd8
  1. 99
      functions/command_stop.sh

99
functions/command_stop.sh

@ -19,7 +19,8 @@ tmux send -t "${servicename}" quit ENTER > /dev/null 2>&1
for seconds in {1..30}; do for seconds in {1..30}; do
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
fn_print_ok_nl "Graceful: rcon quit: ${seconds}" fn_print_ok "Graceful: rcon quit: ${seconds}: "
fn_print_ok_eol_nl
fn_scriptlog "Graceful: rcon quit: OK: ${seconds} seconds" fn_scriptlog "Graceful: rcon quit: OK: ${seconds} seconds"
break break
fi fi
@ -27,7 +28,8 @@ for seconds in {1..30}; do
fn_print_dots "Graceful: rcon quit: ${seconds}" fn_print_dots "Graceful: rcon quit: ${seconds}"
done done
if [ "${pid}" != "0" ]; then if [ "${pid}" != "0" ]; then
fn_print_fail_nl "Graceful: rcon quit" fn_print_fail "Graceful: rcon quit"
fn_print_fail_eol_nl
fn_scriptlog "Graceful: rcon quit: FAIL" fn_scriptlog "Graceful: rcon quit: FAIL"
fn_stop_tmux fn_stop_tmux
fi fi
@ -48,14 +50,16 @@ for seconds in {1..3}; do
sleep 1 sleep 1
fn_print_dots "Graceful: rcon quit: ${seconds}" fn_print_dots "Graceful: rcon quit: ${seconds}"
done done
fn_print_ok_nl "Graceful: rcon quit: ${seconds}" fn_print_ok "Graceful: rcon quit: ${seconds}: "
fn_print_ok_eol_nl
fn_scriptlog "Graceful: rcon quit: OK: ${seconds} seconds"
sleep 1 sleep 1
fn_stop_tmux fn_stop_tmux
} }
# Attempts Graceful of 7 Days To Die using telnet. # Attempts Graceful of 7 Days To Die using telnet.
fn_stop_telnet_sdtd(){ fn_stop_telnet_sdtd(){
sdtdshutdown=$( expect -c ' sdtd_telnet_shutdown=$( expect -c '
proc abort {} { proc abort {} {
puts "Timeout or EOF\n" puts "Timeout or EOF\n"
exit 1 exit 1
@ -72,6 +76,7 @@ expect {
expect { eof } expect { eof }
puts "Completed.\n" puts "Completed.\n"
') ')
} }
fn_stop_graceful_sdtd(){ fn_stop_graceful_sdtd(){
@ -81,60 +86,71 @@ info_config.sh
fn_print_dots "Graceful: telnet" fn_print_dots "Graceful: telnet"
fn_scriptlog "Graceful: telnet" fn_scriptlog "Graceful: telnet"
sleep 1 sleep 1
if [ "${telnetenabled}" == "false" ]; then
# uses localhost on first attempt. fn_print_info_nl "Graceful: telnet: DISABLED: Enable in ${servercfg}"
telnetip=127.0.0.1 elif [ "$(command -v expect)" ]||[ "$(which expect >/dev/null 2>&1)" ]; 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}" fn_print_dots "Graceful: telnet: ${telnetip}"
fn_scriptlog "Graceful: telnet: ${telnetip}" fn_scriptlog "Graceful: telnet: ${telnetip}"
fn_stop_telnet_sdtd
sleep 1
# falls back to the server ip if localhost fails.
refused=$(echo -en "\n ${sdtdshutdown}"| grep "Timeout or EOF")
if [ -n "${refused}" ]; then
fn_print_warn_nl "Graceful: telnet: localhost: "
fn_print_fail_eol
fn_scriptlog "Graceful: telnet: localhost: FAIL"
sleep 1 sleep 1
telnetip=${ip}
fn_print_dots "Graceful: telnet: ${telnetip}"
fn_scriptlog "Graceful: telnet: ${telnetip}"
fn_stop_telnet_sdtd fn_stop_telnet_sdtd
refused=$(echo -en "\n ${sdtdshutdown}"| grep "Timeout or EOF") completed=$(echo -en "\n ${sdtd_telnet_shutdown}"|grep "Completed.")
refused=$(echo -en "\n ${sdtd_telnet_shutdown}"|grep "Timeout or EOF")
fn_print_warnnl "Graceful: telnet: ${telnetip}: " if [ -n "${refused}" ]; then
fn_print_fail_eol fn_print_warn "Graceful: telnet: ${telnetip}: "
fn_print_fail_eol_nl
fn_scriptlog "Graceful: telnet: ${telnetip}: FAIL" fn_scriptlog "Graceful: telnet: ${telnetip}: FAIL"
sleep 1 sleep 1
elif [ -n "${completed}" ]; then
break
fi fi
done
# Checks if attempts have worked. # If telnet was successful will use telnet again to check the connection has closed
completed=$(echo -en "\n ${sdtdshutdown}"| grep "Completed.") # This confirms that the tmux session can now be killed.
if [ -n "${completed}" ]; then if [ -n "${completed}" ]; then
fn_print_ok_nl "Graceful: telnet: " for seconds in {1..30}; do
fn_print_ok_eol fn_stop_telnet_sdtd
fn_scriptlog "Graceful: telnet: OK" refused=$(echo -en "\n ${sdtd_telnet_shutdown}"|grep "Timeout or EOF")
elif [ -n "${refused}" ]; then if [ -n "${refused}" ]; then
fn_print_fail_nl "Graceful: telnet: " fn_print_ok "Graceful: telnet: ${telnetip}: "
fn_print_fail_eol fn_print_ok_eol_nl
fn_scriptlog "Graceful: telnet: ${telnetip}: ${seconds} seconds"
break
fi
sleep 1
fn_print_dots "Graceful: rcon quit: ${seconds}"
done
# If telnet failed will go straight to tmux shutdown.
# If cannot shutdown correctly world save may be lost
else
if [ -n "${refused}" ]; then
fn_print_fail "Graceful: telnet: "
fn_print_fail_eol_nl
fn_scriptlog "Graceful: telnet: ${telnetip}: FAIL" fn_scriptlog "Graceful: telnet: ${telnetip}: FAIL"
echo -en "\n\n" | tee -a "${scriptlog}"
echo -en "Telnet output:" | tee -a "${scriptlog}"
echo -en "\n ${sdtdshutdown}" | tee -a "${scriptlog}"
echo -en "\n\n" | tee -a "${scriptlog}"
else else
fn_print_fail_nl "Graceful: telnet: Unknown error" fn_print_fail_nl "Graceful: telnet: Unknown error"
fn_scriptlog "Graceful: telnet: Unknown error" fn_scriptlog "Graceful: telnet: Unknown error"
fi
echo -en "\n\n" | tee -a "${scriptlog}" echo -en "\n\n" | tee -a "${scriptlog}"
echo -en "Telnet output:" | tee -a "${scriptlog}" echo -en "Telnet output:" | tee -a "${scriptlog}"
echo -en "\n ${sdtdshutdown}" | tee -a "${scriptlog}" echo -en "\n ${sdtd_telnet_shutdown}" | tee -a "${scriptlog}"
echo -en "\n\n" | tee -a "${scriptlog}" echo -en "\n\n" | tee -a "${scriptlog}"
fi fi
else
fn_print_dots "Graceful: telnet: "
fn_scriptlog "Graceful: telnet: "
fn_print_fail "Graceful: telnet: expect not installed: "
fn_print_fail_eol_nl
fn_scriptlog "Graceful: telnet: expect not installed: FAIL"
fi
sleep 1
fn_stop_tmux
} }
fn_stop_graceful_select(){ fn_stop_graceful_select(){
if [ "${gamename}" == "7 Days to Die" ]; then if [ "${gamename}" == "7 Days To Die" ]; then
fn_stop_graceful_sdtd fn_stop_graceful_sdtd
elif [ "${engine}" == "source" ]; then elif [ "${engine}" == "source" ]; then
fn_stop_graceful_source fn_stop_graceful_source
@ -162,18 +178,17 @@ fn_scriptlog "tmux kill-session: ${servername}"
sleep 1 sleep 1
# Kill tmux session # Kill tmux session
tmux kill-session -t "${servicename}" > /dev/null 2>&1 tmux kill-session -t "${servicename}" > /dev/null 2>&1
sleep 0.5
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
fn_print_ok_nl "${servername}"
fn_scriptlog "Stopped ${servername}"
sleep 1
# Remove lock file # Remove lock file
rm -f "${rootdir}/${lockselfname}" rm -f "${rootdir}/${lockselfname}"
fn_print_ok_nl "${servername}"
fn_scriptlog "Stopped ${servername}"
else else
fn_print_fail_nl "Unable to stop${servername}" fn_print_fail_nl "Unable to stop${servername}"
fn_scriptlog "Unable to stop${servername}" fn_scriptlog "Unable to stop${servername}"
fi fi
} }
# checks if the server is already stopped before trying to stop. # checks if the server is already stopped before trying to stop.

Loading…
Cancel
Save