From d39fc9f01c75b7c48268f18cb66f8edeb5fdaed2 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Mon, 26 Oct 2015 15:26:25 +0000 Subject: [PATCH] Graceful quit for source and goldsrc added fn_stop will attempt to shutdown source and goldsource gracefully before using tmux shutdown. --- functions/fn_stop | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/functions/fn_stop b/functions/fn_stop index 72a5aa13c..2270914eb 100644 --- a/functions/fn_stop +++ b/functions/fn_stop @@ -2,7 +2,7 @@ # LGSM fn_stop function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 180615 +# Version: 261015 # Description: Stops the server. @@ -28,7 +28,6 @@ sdtd_telnet(){ ') } - fn_stop_teamspeak3(){ fn_check_root fn_check_systemdir @@ -65,8 +64,6 @@ if [ "${gamename}" == "7 Days To Die" ] ; then fn_printdots "Attempting graceful shutdown via telnet" fn_scriptlog "Attempting graceful shutdown via telnet" sleep 1 - - telnetip=127.0.0.1 sdtd_telnet @@ -124,9 +121,30 @@ else fn_printfail "${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else - tmux send -t "${servicename}" quit ENTER - sleep 20 - tmux kill-session -t "${servicename}" + + if [ "${engine}" == "source" ]||[ "${engine}" == "goldsource" ]; then + sleep 1 + fn_printdots "Attempting graceful shutdown" + fn_scriptlog "Attempting graceful shutdown" + tmux send -t "${servicename}" quit ENTER > /dev/null 2>&1 + counter=0 + while [ "${pid}" != "0" ]; do + pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") + sleep 1 + let counter=counter+1 + if [ "${counter}" -gt "1" ];then + fn_printdots "Attempting graceful shutdown: ${counter}" + fi + done + pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") + if [ "${pid}" == "0" ];then + fn_printok "Attempting graceful shutdown" + else + fn_printfail "Attempting graceful shutdown" + fi + fi + + tmux kill-session -t "${servicename}" > /dev/null 2>&1 fn_printok "${servername}" fn_scriptlog "Stopped ${servername}" fi @@ -141,4 +159,4 @@ if [ "${gamename}" == "Teamspeak 3" ]; then fn_stop_teamspeak3 else fn_stop_tmux -fi +fi \ No newline at end of file