From 8008501f5ad22c7172dd23c5c255212320e312a0 Mon Sep 17 00:00:00 2001 From: Marvin Lehmann Date: Thu, 11 May 2017 20:21:19 +0200 Subject: [PATCH] Added graceful shutdown for Terraria --- lgsm/functions/command_stop.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lgsm/functions/command_stop.sh b/lgsm/functions/command_stop.sh index 1443fac8d..37cc54c11 100644 --- a/lgsm/functions/command_stop.sh +++ b/lgsm/functions/command_stop.sh @@ -228,6 +228,34 @@ fn_stop_graceful_mta(){ fn_stop_tmux } +# Attempts graceful of source using rcon 'exit' command. +fn_stop_graceful_terraria(){ + fn_print_dots "Graceful: sending \"exit\"" + fn_script_log_info "Graceful: sending \"exit\"" + # sends exit + tmux send -t "${servicename}" exit ENTER > /dev/null 2>&1 + # waits up to 30 seconds giving the server time to shutdown gracefuly + for seconds in {1..30}; do + check_status.sh + if [ "${status}" == "0" ]; then + fn_print_ok "Graceful: sending \"exit\": ${seconds}: " + fn_print_ok_eol_nl + fn_script_log_pass "Graceful: sending \"exit\": OK: ${seconds} seconds" + break + fi + sleep 1 + fn_print_dots "Graceful: sending \"exit\": ${seconds}" + done + check_status.sh + if [ "${status}" != "0" ]; then + fn_print_error "Graceful: sending \"exit\": " + fn_print_fail_eol_nl + fn_script_log_error "Graceful: sending \"exit\": FAIL" + fi + sleep 1 + fn_stop_tmux +} + fn_stop_graceful_select(){ if [ "${gamename}" == "7 Days To Die" ]; then fn_stop_graceful_sdtd @@ -241,6 +269,8 @@ fn_stop_graceful_select(){ fn_stop_graceful_minecraft elif [ "${engine}" == "renderware" ]; then fn_stop_graceful_mta + elif [ "${engine}" == "terraria" ]; then + fn_stop_graceful_terraria else fn_stop_tmux fi