From ce643656871fdf2221d8179bd52f1545b36ea2f1 Mon Sep 17 00:00:00 2001 From: cedarlug Date: Fri, 20 May 2016 18:28:42 -0500 Subject: [PATCH 1/8] Adding shutdown tweaks for Ark server --- functions/command_stop.sh | 219 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 functions/command_stop.sh diff --git a/functions/command_stop.sh b/functions/command_stop.sh new file mode 100644 index 000000000..bb886cd0c --- /dev/null +++ b/functions/command_stop.sh @@ -0,0 +1,219 @@ +#!/bin/bash +# LGSM command_stop.sh function +# Author: Daniel Gibbs +# Website: http://gameservermanagers.com +lgsm_version="271215" + +# Description: Stops the server. + +local modulename="Stopping" +function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" + +sdtd_telnet(){ + sdtdshutdown=$( expect -c ' + proc abort {} { + puts "Timeout or EOF\n" + exit 1 + } + spawn telnet '"${telnetip}"' '"${telnetport}"' + expect { + "password:" { send "'"${telnetpass}"'\r" } + default abort + } + expect { + "session." { send "shutdown\r" } + default abort + } + expect { eof } + puts "Completed.\n" + ') +} + +fn_stop_ark(){ + # grab the queryport. there are two locations to grab this from. + # first start with the parameters from the parms line + fn_printwarn "attempting to determine any in-use ports" + fn_scriptlog "attempting to determine any in-use ports" + port=$(grep ^parms= ${servername} |\ + awk -f"queryport=" '{print $2}' |\ + sed "s/[^[:digit:].*].*//g" ) + + echo port is $port + read a + if [ -z $port ] ; then + fn_printwarn "no port found in the ${servername} script" + fn_scriptlog "no port found in the ${servername} script" + userconfigfile="${filesdir}" + userconfigfile+="/serverfiles/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini" + port=$(grep ^QueryPort= ${userconfigfile} | cut -d= -f2 | sed "s/[^[:digit:].*].*//g") + fi + echo port is $port + read b + if [ -z $port ] ; then + fn_printwarn "no port found in the GameUsersettings.ini file" + fn_scriptlog "no port found in the GameUsersettings.ini file" + return + fi + + if [[ ${#port} -gt 0 ]] ; then + # pid=$(lsof -ti udp:${port}) + # might need netstat here if lsof isn't installed. + # netstat variation: + pid=$(netstat -nap 2>/dev/null | grep ^udp[:space:] |\ + grep :${port}[[:space:]] | rev | awk '{print $1}' |\ + rev | cut -d\/ -f1) + echo pid is $pid + read c + # + # check for a valid pid + let pid+=0 # turns an empty string into a valid number, '0', + # and a valid numeric pid remains unchanged. + if [[ $pid -gt 1 && $pid -le $(cat /proc/sys/kernel/pid_max) ]] ; then + # kill the process still listening on that port. + # kill -9 $pid + while kill -0 $pid + do + echo "kill code id $?" + read d + fn_printwarn "process is still bound to the port" + fn_scriptlog "process is still bound to the port" + sleep 1 + fn_printdots "${servername}" + fn_scriptlog "${servername}" + done + fi # end if for pid range check + fi # end if for port check +} # end of fn_stop_ark + + +fn_stop_teamspeak3(){ +check.sh +fn_printdots "${servername}" +fn_scriptlog "${servername}" +sleep 1 +info_ts3status.sh +if [ "${ts3status}" = "No server running (ts3server.pid is missing)" ]; then + fn_printfail "${servername} is already stopped" + fn_scriptlog "${servername} is already stopped" +else + ${filesdir}/ts3server_startscript.sh stop > /dev/null 2>&1 + fn_printok "${servername}" + fn_scriptlog "Stopped ${servername}" +fi +# Remove lock file +rm -f "${rootdir}/${lockselfname}" +sleep 1 +echo -en "\n" +} + +fn_stop_tmux(){ +check.sh +info_config.sh +fn_printdots "${servername}" +fn_scriptlog "${servername}" +sleep 1 + +if [ "${gamename}" == "7 Days To Die" ] ; then + # if game is 7 Days To Die, we need special, graceful shutdown via telnet connection. + # Set below variable to be called for expect to operate correctly.. + fn_printdots "Attempting graceful shutdown via telnet" + fn_scriptlog "Attempting graceful shutdown via telnet" + sleep 1 + telnetip=127.0.0.1 + sdtd_telnet + + # If failed using localhost will use servers ip + refused=$(echo -en "\n ${sdtdshutdown}"| grep "Timeout or EOF") + if [ -n "${refused}" ]; then + telnetip=${ip} + fn_printwarn "Attempting graceful shutdown via telnet: localhost failed" + fn_scriptlog "Warning! Attempting graceful shutdown failed using localhost" + sleep 5 + echo -en "\n" + fn_printdots "Attempting graceful shutdown via telnet: using ${telnetip}" + fn_scriptlog "Attempting graceful shutdown via telnet using ${telnetip}" + sdtd_telnet + sleep 1 + fi + + refused=$(echo -en "\n ${sdtdshutdown}"| grep "Timeout or EOF") + completed=$(echo -en "\n ${sdtdshutdown}"| grep "Completed.") + if [ -n "${refused}" ]; then + fn_printfail "Attempting graceful shutdown via telnet" + fn_scriptlog "Attempting graceful shutdown failed" + fn_scriptlog "${refused}" + elif [ -n "${completed}" ]; then + fn_printok "Attempting graceful shutdown via telnet" + fn_scriptlog "Attempting graceful shutdown succeeded" + else + fn_printfail "Attempting graceful shutdown via telnet: Unknown error" + fn_scriptlog "Attempting graceful shutdown failed" + fn_scriptlog "Unknown error" + fi + sleep 1 + echo -en "\n\n" + echo -en "Telnet output:" + echo -en "\n ${sdtdshutdown}" + echo -en "\n\n" + sleep 1 + fn_printdots "${servername}" + fn_scriptlog "${servername}" + sleep 5 + pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") + if [ "${pid}" == "0" ]; then + fn_printok "${servername} is already stopped using graceful shutdown" + fn_scriptlog "${servername} is already stopped using graceful shutdown" + else + tmux kill-session -t "${servicename}" + fn_printok "${servername}" + fn_scriptlog "Stopped ${servername}" + fi + +else + pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") + if [ "${pid}" == "0" ]; then + fn_printfail "${servername} is already stopped" + fn_scriptlog "${servername} is already stopped" + else + + 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" -a $counter -lt 30 ]; 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 +fi + # Remove lock file + rm -f "${rootdir}/${lockselfname}" + sleep 1 + echo -en "\n" +} + +if [ "${gamename}" == "Teamspeak 3" ]; then + fn_stop_teamspeak3 +else + fn_stop_tmux + if [ "${gamename}" == "ARK: Survivial Evolved" ]; then + fn_stop_ark + fi +fi From bab4a1c6c379ccbd0fdf5ac700180c8baa5ff4dc Mon Sep 17 00:00:00 2001 From: cedarlug Date: Fri, 20 May 2016 18:36:50 -0500 Subject: [PATCH 2/8] Removing the debug pauses --- functions/command_stop.sh | 60 ++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/functions/command_stop.sh b/functions/command_stop.sh index bb886cd0c..3deb8c12a 100644 --- a/functions/command_stop.sh +++ b/functions/command_stop.sh @@ -34,54 +34,41 @@ fn_stop_ark(){ # first start with the parameters from the parms line fn_printwarn "attempting to determine any in-use ports" fn_scriptlog "attempting to determine any in-use ports" - port=$(grep ^parms= ${servername} |\ - awk -f"queryport=" '{print $2}' |\ - sed "s/[^[:digit:].*].*//g" ) - - echo port is $port - read a - if [ -z $port ] ; then - fn_printwarn "no port found in the ${servername} script" - fn_scriptlog "no port found in the ${servername} script" + #port=$(grep ^parms= arkserver |\ + # awk -F"QueryPort=" '{print $2}' |\ + # sed "s/[^[:digit:].*].*//g" ) + info_config.sh + if [ -z $queryport ] ; then + fn_printwarn "no queryport found in the arkserver script" + fn_scriptlog "no queryport found in the arkserver script" userconfigfile="${filesdir}" - userconfigfile+="/serverfiles/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini" + userconfigfile+="/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini" port=$(grep ^QueryPort= ${userconfigfile} | cut -d= -f2 | sed "s/[^[:digit:].*].*//g") fi - echo port is $port - read b - if [ -z $port ] ; then - fn_printwarn "no port found in the GameUsersettings.ini file" - fn_scriptlog "no port found in the GameUsersettings.ini file" + if [ -z $queryport ] ; then + fn_printwarn "no queryport found in the GameUsersettings.ini file" + fn_scriptlog "no queryport found in the GameUsersettings.ini file" return fi if [[ ${#port} -gt 0 ]] ; then - # pid=$(lsof -ti udp:${port}) - # might need netstat here if lsof isn't installed. - # netstat variation: - pid=$(netstat -nap 2>/dev/null | grep ^udp[:space:] |\ - grep :${port}[[:space:]] | rev | awk '{print $1}' |\ + fn_printwarn "QueryPort $queryport found in the configs. Checking to see if it's still bound." + fn_scriptlog "QueryPort $queryport found in the configs. Checking to see if it's still bound." + pid=$(netstat -nap 2>/dev/null | grep ^udp[[:space:]] |\ + grep :${queryport}[[:space:]] | rev | awk '{print $1}' |\ rev | cut -d\/ -f1) - echo pid is $pid - read c # # check for a valid pid let pid+=0 # turns an empty string into a valid number, '0', # and a valid numeric pid remains unchanged. if [[ $pid -gt 1 && $pid -le $(cat /proc/sys/kernel/pid_max) ]] ; then # kill the process still listening on that port. - # kill -9 $pid - while kill -0 $pid - do - echo "kill code id $?" - read d - fn_printwarn "process is still bound to the port" - fn_scriptlog "process is still bound to the port" - sleep 1 - fn_printdots "${servername}" - fn_scriptlog "${servername}" - done + fn_printdots "Killing process $pid" + fn_scriptlog "Killing process $pid" + kill -9 $pid fi # end if for pid range check + fn_printok "${servername} stopped and ports cleared" + fn_scriptlog "Ports cleared for ${servername}" fi # end if for port check } # end of fn_stop_ark @@ -213,7 +200,8 @@ if [ "${gamename}" == "Teamspeak 3" ]; then fn_stop_teamspeak3 else fn_stop_tmux - if [ "${gamename}" == "ARK: Survivial Evolved" ]; then - fn_stop_ark - fi + if [ "${gamename}" == "ARK: Survivial Evolved" ]; then + fn_stop_ark + echo -en "\n" + fi fi From eb20cae44af9c54fef463ae0da2b0f4b6913256c Mon Sep 17 00:00:00 2001 From: cedarlug Date: Fri, 20 May 2016 18:40:30 -0500 Subject: [PATCH 3/8] Removing comments relating to parsing of the script (which is no longer performed) --- functions/command_stop.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/functions/command_stop.sh b/functions/command_stop.sh index 3deb8c12a..baa907a0d 100644 --- a/functions/command_stop.sh +++ b/functions/command_stop.sh @@ -30,13 +30,8 @@ sdtd_telnet(){ } fn_stop_ark(){ - # grab the queryport. there are two locations to grab this from. - # first start with the parameters from the parms line fn_printwarn "attempting to determine any in-use ports" fn_scriptlog "attempting to determine any in-use ports" - #port=$(grep ^parms= arkserver |\ - # awk -F"QueryPort=" '{print $2}' |\ - # sed "s/[^[:digit:].*].*//g" ) info_config.sh if [ -z $queryport ] ; then fn_printwarn "no queryport found in the arkserver script" @@ -175,7 +170,7 @@ else let counter=counter+1 if [ "${counter}" -gt "1" ]; then fn_printdots "Attempting graceful shutdown: ${counter}" - fi + fi done pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") if [ "${pid}" == "0" ]; then From 9d6c9574a6095aa51e13cd0cb50751c0f718580a Mon Sep 17 00:00:00 2001 From: cedarlug Date: Sat, 21 May 2016 06:34:15 -0500 Subject: [PATCH 4/8] This does not belong here. --- functions/command_stop.sh | 202 -------------------------------------- 1 file changed, 202 deletions(-) delete mode 100644 functions/command_stop.sh diff --git a/functions/command_stop.sh b/functions/command_stop.sh deleted file mode 100644 index baa907a0d..000000000 --- a/functions/command_stop.sh +++ /dev/null @@ -1,202 +0,0 @@ -#!/bin/bash -# LGSM command_stop.sh function -# Author: Daniel Gibbs -# Website: http://gameservermanagers.com -lgsm_version="271215" - -# Description: Stops the server. - -local modulename="Stopping" -function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" - -sdtd_telnet(){ - sdtdshutdown=$( expect -c ' - proc abort {} { - puts "Timeout or EOF\n" - exit 1 - } - spawn telnet '"${telnetip}"' '"${telnetport}"' - expect { - "password:" { send "'"${telnetpass}"'\r" } - default abort - } - expect { - "session." { send "shutdown\r" } - default abort - } - expect { eof } - puts "Completed.\n" - ') -} - -fn_stop_ark(){ - fn_printwarn "attempting to determine any in-use ports" - fn_scriptlog "attempting to determine any in-use ports" - info_config.sh - if [ -z $queryport ] ; then - fn_printwarn "no queryport found in the arkserver script" - fn_scriptlog "no queryport found in the arkserver script" - userconfigfile="${filesdir}" - userconfigfile+="/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini" - port=$(grep ^QueryPort= ${userconfigfile} | cut -d= -f2 | sed "s/[^[:digit:].*].*//g") - fi - if [ -z $queryport ] ; then - fn_printwarn "no queryport found in the GameUsersettings.ini file" - fn_scriptlog "no queryport found in the GameUsersettings.ini file" - return - fi - - if [[ ${#port} -gt 0 ]] ; then - fn_printwarn "QueryPort $queryport found in the configs. Checking to see if it's still bound." - fn_scriptlog "QueryPort $queryport found in the configs. Checking to see if it's still bound." - pid=$(netstat -nap 2>/dev/null | grep ^udp[[:space:]] |\ - grep :${queryport}[[:space:]] | rev | awk '{print $1}' |\ - rev | cut -d\/ -f1) - # - # check for a valid pid - let pid+=0 # turns an empty string into a valid number, '0', - # and a valid numeric pid remains unchanged. - if [[ $pid -gt 1 && $pid -le $(cat /proc/sys/kernel/pid_max) ]] ; then - # kill the process still listening on that port. - fn_printdots "Killing process $pid" - fn_scriptlog "Killing process $pid" - kill -9 $pid - fi # end if for pid range check - fn_printok "${servername} stopped and ports cleared" - fn_scriptlog "Ports cleared for ${servername}" - fi # end if for port check -} # end of fn_stop_ark - - -fn_stop_teamspeak3(){ -check.sh -fn_printdots "${servername}" -fn_scriptlog "${servername}" -sleep 1 -info_ts3status.sh -if [ "${ts3status}" = "No server running (ts3server.pid is missing)" ]; then - fn_printfail "${servername} is already stopped" - fn_scriptlog "${servername} is already stopped" -else - ${filesdir}/ts3server_startscript.sh stop > /dev/null 2>&1 - fn_printok "${servername}" - fn_scriptlog "Stopped ${servername}" -fi -# Remove lock file -rm -f "${rootdir}/${lockselfname}" -sleep 1 -echo -en "\n" -} - -fn_stop_tmux(){ -check.sh -info_config.sh -fn_printdots "${servername}" -fn_scriptlog "${servername}" -sleep 1 - -if [ "${gamename}" == "7 Days To Die" ] ; then - # if game is 7 Days To Die, we need special, graceful shutdown via telnet connection. - # Set below variable to be called for expect to operate correctly.. - fn_printdots "Attempting graceful shutdown via telnet" - fn_scriptlog "Attempting graceful shutdown via telnet" - sleep 1 - telnetip=127.0.0.1 - sdtd_telnet - - # If failed using localhost will use servers ip - refused=$(echo -en "\n ${sdtdshutdown}"| grep "Timeout or EOF") - if [ -n "${refused}" ]; then - telnetip=${ip} - fn_printwarn "Attempting graceful shutdown via telnet: localhost failed" - fn_scriptlog "Warning! Attempting graceful shutdown failed using localhost" - sleep 5 - echo -en "\n" - fn_printdots "Attempting graceful shutdown via telnet: using ${telnetip}" - fn_scriptlog "Attempting graceful shutdown via telnet using ${telnetip}" - sdtd_telnet - sleep 1 - fi - - refused=$(echo -en "\n ${sdtdshutdown}"| grep "Timeout or EOF") - completed=$(echo -en "\n ${sdtdshutdown}"| grep "Completed.") - if [ -n "${refused}" ]; then - fn_printfail "Attempting graceful shutdown via telnet" - fn_scriptlog "Attempting graceful shutdown failed" - fn_scriptlog "${refused}" - elif [ -n "${completed}" ]; then - fn_printok "Attempting graceful shutdown via telnet" - fn_scriptlog "Attempting graceful shutdown succeeded" - else - fn_printfail "Attempting graceful shutdown via telnet: Unknown error" - fn_scriptlog "Attempting graceful shutdown failed" - fn_scriptlog "Unknown error" - fi - sleep 1 - echo -en "\n\n" - echo -en "Telnet output:" - echo -en "\n ${sdtdshutdown}" - echo -en "\n\n" - sleep 1 - fn_printdots "${servername}" - fn_scriptlog "${servername}" - sleep 5 - pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") - if [ "${pid}" == "0" ]; then - fn_printok "${servername} is already stopped using graceful shutdown" - fn_scriptlog "${servername} is already stopped using graceful shutdown" - else - tmux kill-session -t "${servicename}" - fn_printok "${servername}" - fn_scriptlog "Stopped ${servername}" - fi - -else - pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") - if [ "${pid}" == "0" ]; then - fn_printfail "${servername} is already stopped" - fn_scriptlog "${servername} is already stopped" - else - - 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" -a $counter -lt 30 ]; 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 -fi - # Remove lock file - rm -f "${rootdir}/${lockselfname}" - sleep 1 - echo -en "\n" -} - -if [ "${gamename}" == "Teamspeak 3" ]; then - fn_stop_teamspeak3 -else - fn_stop_tmux - if [ "${gamename}" == "ARK: Survivial Evolved" ]; then - fn_stop_ark - echo -en "\n" - fi -fi From 1c7b38738fbcebf9ab6390bfbd1c43379a8c143f Mon Sep 17 00:00:00 2001 From: cedarlug Date: Sat, 21 May 2016 06:54:11 -0500 Subject: [PATCH 5/8] Simple typo with omitted '=' - breaks functionality --- ARKSurvivalEvolved/arkserver | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ARKSurvivalEvolved/arkserver b/ARKSurvivalEvolved/arkserver index 17e3e5d78..8a19c7d32 100644 --- a/ARKSurvivalEvolved/arkserver +++ b/ARKSurvivalEvolved/arkserver @@ -22,7 +22,7 @@ email="email@example.com" # Pushbullet # https://www.pushbullet.com/#settings -pushbulletalert"off" +pushbulletalert="off" pushbullettoken="accesstoken" # Steam login From 6dc74cdf99d122d550243d5398de1e1f2a3999c9 Mon Sep 17 00:00:00 2001 From: cedarlug Date: Sun, 22 May 2016 17:23:30 -0500 Subject: [PATCH 6/8] Folding Ark stop functionality into development paradigm --- lgsm/functions/command_stop.sh | 82 +++++++++++++++++++++++++++------- 1 file changed, 67 insertions(+), 15 deletions(-) diff --git a/lgsm/functions/command_stop.sh b/lgsm/functions/command_stop.sh index 1f941eb36..b37346c33 100644 --- a/lgsm/functions/command_stop.sh +++ b/lgsm/functions/command_stop.sh @@ -2,7 +2,7 @@ # LGSM command_stop.sh function # Author: Daniel Gibbs # Website: https://gameservermanagers.com -lgsm_version="271215" +lgsm_version="210516" # Description: Stops the server. @@ -17,8 +17,8 @@ fn_stop_graceful_source(){ tmux send -t "${servicename}" quit ENTER > /dev/null 2>&1 # waits up to 30 seconds giving the server time to shutdown gracefuly for seconds in {1..30}; do - pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") - if [ "${pid}" == "0" ]; then + check_status.sh + if [ "${status}" == "0" ]; then fn_print_ok "Graceful: rcon quit: ${seconds}: " fn_print_ok_eol_nl fn_scriptlog "Graceful: rcon quit: OK: ${seconds} seconds" @@ -27,7 +27,8 @@ fn_stop_graceful_source(){ sleep 1 fn_print_dots "Graceful: rcon quit: ${seconds}" done - if [ "${pid}" != "0" ]; then + check_status.sh + if [ "${status}" != "0" ]; then fn_print_fail "Graceful: rcon quit: " fn_print_fail_eol_nl fn_scriptlog "Graceful: rcon quit: FAIL" @@ -158,28 +159,79 @@ fn_stop_graceful_select(){ fi } +fn_stop_ark(){ + info_config.sh + if [ -z $queryport ] ; then + fn_print_warn "no queryport found using info_config.sh" + userconfigfile="${filesdir}" + userconfigfile+="/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini" + queryport=$(grep ^QueryPort= ${userconfigfile} | cut -d= -f2 | sed "s/[^[:digit:].*].*//g") + fi + if [ -z $queryport ] ; then + fn_print_warn "no queryport found in the GameUsersettings.ini file" + return + fi + + if [[ ${#queryport} -gt 0 ]] ; then + for ((pidcheck=0;pidcheck<20;pidcheck++)) ; do + pid=$(netstat -nap 2>/dev/null | grep ^udp[[:space:]] |\ + grep :${queryport}[[:space:]] | rev | awk '{print $1}' |\ + rev | cut -d\/ -f1) + # + # check for a valid pid + let pid+=0 # turns an empty string into a valid number, '0', + # and a valid numeric pid remains unchanged. + if [[ $pid -gt 1 && $pid -le $(cat /proc/sys/kernel/pid_max) ]] ; then + fn_print_dots "Process still bound. Awaiting graceful exit: $pidcheck" + sleep 1 + else + break // Our job is done here + fi # end if for pid range check + done + if [[ ${pidcheck} -eq 20 ]] ; then + # The process doesn't want to close after 20 seconds. + # kill it hard. + fn_print_warn "Terminating reluctant Ark process: $pid" + kill -9 $pid + fi + fi # end if for port check +} # end of fn_stop_ark + + fn_stop_teamspeak3(){ fn_print_dots "${servername}" fn_scriptlog "${servername}" sleep 1 ${filesdir}/ts3server_startscript.sh stop > /dev/null 2>&1 - # Remove lock file - rm -f "${rootdir}/${lockselfname}" - fn_print_ok_nl "${servername}" - fn_scriptlog "Stopped ${servername}" - } + check_status.sh + if [ "${status}" == "0" ]; then + # Remove lock file + rm -f "${rootdir}/${lockselfname}" + fn_print_ok_nl "${servername}" + fn_scriptlog "Stopped ${servername}" + else + fn_print_fail_nl "Unable to stop${servername}" + fn_scriptlog "Unable to stop${servername}" + fi +} - fn_stop_tmux(){ +fn_stop_tmux(){ fn_print_dots "${servername}" fn_scriptlog "tmux kill-session: ${servername}" sleep 1 # Kill tmux session tmux kill-session -t "${servicename}" > /dev/null 2>&1 sleep 0.5 - pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") - if [ "${pid}" == "0" ]; then + check_status.sh + if [ "${status}" == "0" ]; then # Remove lock file rm -f "${rootdir}/${lockselfname}" + # ARK doesn't clean up immediately after tmux is killed. + # Make certain the ports are cleared before continuing. + if [ "${gamename}" == "ARK: Survivial Evolved" ]; then + fn_stop_ark + echo -en "\n" + fi fn_print_ok_nl "${servername}" fn_scriptlog "Stopped ${servername}" else @@ -199,8 +251,8 @@ fn_stop_pre_check(){ fn_stop_teamspeak3 fi else - pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") - if [ "${pid}" == "0" ]; then + check_status.sh + if [ "${status}" == "0" ]; then fn_print_ok_nl "${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else @@ -214,4 +266,4 @@ info_config.sh fn_print_dots "${servername}" fn_scriptlog "${servername}" sleep 1 -fn_stop_pre_check \ No newline at end of file +fn_stop_pre_check From cdefc548cde4abfa892eae944a2c340b0bf93338 Mon Sep 17 00:00:00 2001 From: cedarlug Date: Sun, 22 May 2016 17:54:18 -0500 Subject: [PATCH 7/8] Formalizing countup check and reverting upstream changes --- lgsm/functions/command_stop.sh | 89 ++++++++++++++++------------------ 1 file changed, 41 insertions(+), 48 deletions(-) diff --git a/lgsm/functions/command_stop.sh b/lgsm/functions/command_stop.sh index b37346c33..d7b9ddd33 100644 --- a/lgsm/functions/command_stop.sh +++ b/lgsm/functions/command_stop.sh @@ -17,8 +17,8 @@ fn_stop_graceful_source(){ tmux send -t "${servicename}" quit 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 + pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") + if [ "${pid}" == "0" ]; then fn_print_ok "Graceful: rcon quit: ${seconds}: " fn_print_ok_eol_nl fn_scriptlog "Graceful: rcon quit: OK: ${seconds} seconds" @@ -27,8 +27,7 @@ fn_stop_graceful_source(){ sleep 1 fn_print_dots "Graceful: rcon quit: ${seconds}" done - check_status.sh - if [ "${status}" != "0" ]; then + if [ "${pid}" != "0" ]; then fn_print_fail "Graceful: rcon quit: " fn_print_fail_eol_nl fn_scriptlog "Graceful: rcon quit: FAIL" @@ -156,10 +155,11 @@ fn_stop_graceful_select(){ fn_stop_graceful_goldsource else fn_stop_tmux - fi + fi } fn_stop_ark(){ + MAXPIDITER=15 # The maximum number of times to check if the ark pid has closed gracefully. info_config.sh if [ -z $queryport ] ; then fn_print_warn "no queryport found using info_config.sh" @@ -173,47 +173,40 @@ fn_stop_ark(){ fi if [[ ${#queryport} -gt 0 ]] ; then - for ((pidcheck=0;pidcheck<20;pidcheck++)) ; do - pid=$(netstat -nap 2>/dev/null | grep ^udp[[:space:]] |\ - grep :${queryport}[[:space:]] | rev | awk '{print $1}' |\ - rev | cut -d\/ -f1) - # - # check for a valid pid - let pid+=0 # turns an empty string into a valid number, '0', - # and a valid numeric pid remains unchanged. - if [[ $pid -gt 1 && $pid -le $(cat /proc/sys/kernel/pid_max) ]] ; then - fn_print_dots "Process still bound. Awaiting graceful exit: $pidcheck" - sleep 1 - else - break // Our job is done here - fi # end if for pid range check - done - if [[ ${pidcheck} -eq 20 ]] ; then - # The process doesn't want to close after 20 seconds. - # kill it hard. - fn_print_warn "Terminating reluctant Ark process: $pid" + for (( pidcheck=0 ; pidcheck < ${MADPIDITER} ; pidcheck++ )) ; do + pid=$(netstat -nap 2>/dev/null | grep ^udp[[:space:]] |\ + grep :${queryport}[[:space:]] | rev | awk '{print $1}' |\ + rev | cut -d\/ -f1) + # + # check for a valid pid + let pid+=0 # turns an empty string into a valid number, '0', + # and a valid numeric pid remains unchanged. + if [[ $pid -gt 1 && $pid -le $(cat /proc/sys/kernel/pid_max) ]] ; then + fn_print_dots "Process still bound. Awaiting graceful exit: $pidcheck" + sleep 1 + else + break # Our job is done here + fi # end if for pid range check + done + if [[ ${pidcheck} -eq ${MAXPIDITER} ]] ; then + # The process doesn't want to close after 20 seconds. + # kill it hard. + fn_print_warn "Terminating reluctant Ark process: $pid" kill -9 $pid - fi - fi # end if for port check + fi + fi # end if for port check } # end of fn_stop_ark - fn_stop_teamspeak3(){ fn_print_dots "${servername}" fn_scriptlog "${servername}" sleep 1 ${filesdir}/ts3server_startscript.sh stop > /dev/null 2>&1 - check_status.sh - if [ "${status}" == "0" ]; then - # Remove lock file - rm -f "${rootdir}/${lockselfname}" - fn_print_ok_nl "${servername}" - fn_scriptlog "Stopped ${servername}" - else - fn_print_fail_nl "Unable to stop${servername}" - fn_scriptlog "Unable to stop${servername}" - fi -} + # Remove lock file + rm -f "${rootdir}/${lockselfname}" + fn_print_ok_nl "${servername}" + fn_scriptlog "Stopped ${servername}" + } fn_stop_tmux(){ fn_print_dots "${servername}" @@ -222,16 +215,16 @@ fn_stop_tmux(){ # Kill tmux session tmux kill-session -t "${servicename}" > /dev/null 2>&1 sleep 0.5 - check_status.sh - if [ "${status}" == "0" ]; then + pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") + if [ "${pid}" == "0" ]; then # Remove lock file rm -f "${rootdir}/${lockselfname}" # ARK doesn't clean up immediately after tmux is killed. - # Make certain the ports are cleared before continuing. - if [ "${gamename}" == "ARK: Survivial Evolved" ]; then - fn_stop_ark - echo -en "\n" - fi + # Make certain the ports are cleared before continuing. + if [ "${gamename}" == "ARK: Survivial Evolved" ]; then + fn_stop_ark + echo -en "\n" + fi fn_print_ok_nl "${servername}" fn_scriptlog "Stopped ${servername}" else @@ -249,10 +242,10 @@ fn_stop_pre_check(){ fn_scriptlog "${servername} is already stopped" else fn_stop_teamspeak3 - fi + fi else - check_status.sh - if [ "${status}" == "0" ]; then + pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") + if [ "${pid}" == "0" ]; then fn_print_ok_nl "${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else From 9f638e8fbb9587d958bd24a003546e3e7986e1bc Mon Sep 17 00:00:00 2001 From: cedarlug Date: Sun, 22 May 2016 22:21:48 -0500 Subject: [PATCH 8/8] Correcing reference to fn_fetch_function --- lgsm/functions/core_functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/core_functions.sh b/lgsm/functions/core_functions.sh index c7d4451bc..59aad2dd4 100644 --- a/lgsm/functions/core_functions.sh +++ b/lgsm/functions/core_functions.sh @@ -148,7 +148,7 @@ fn_fetch_function command_fastdl.sh(){ functionfile="${FUNCNAME}" -fn_runfunction +fn_fetch_function } command_ts3_server_pass.sh(){