Browse Source

Added graceful stop for all unreal engine servers

pull/1310/head
Daniel Gibbs 8 years ago
parent
commit
4f75192b6c
  1. 89
      lgsm/functions/command_stop.sh

89
lgsm/functions/command_stop.sh

@ -221,7 +221,7 @@ fn_stop_graceful_mta(){
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 [ "${gamename}" == "Factorio" ]; then elif [ "${gamename}" == "Factorio" ]||[ "${engine}" == "unreal4" ]||[ "${engine}" == "unreal3" ]||[ "${engine}" == "unreal2" ]||[ "${engine}" == "unreal" ]; then
fn_stop_graceful_ctrlc fn_stop_graceful_ctrlc
elif [ "${engine}" == "source" ]; then elif [ "${engine}" == "source" ]; then
fn_stop_graceful_source fn_stop_graceful_source
@ -231,53 +231,51 @@ fn_stop_graceful_select(){
fn_stop_graceful_minecraft fn_stop_graceful_minecraft
elif [ "${engine}" == "renderware" ]; then elif [ "${engine}" == "renderware" ]; then
fn_stop_graceful_mta fn_stop_graceful_mta
elif [ "${engine}" == "unreal4" ]; then
fn_stop_graceful_ctrlc
else else
fn_stop_tmux fn_stop_tmux
fi fi
} }
fn_stop_ark(){ fn_stop_ark(){
maxpiditer=15 # The maximum number of times to check if the ark pid has closed gracefully. maxpiditer=15 # The maximum number of times to check if the ark pid has closed gracefully.
info_config.sh info_config.sh
if [ -z "${queryport}" ]; then if [ -z "${queryport}" ]; then
fn_print_warn "No queryport found using info_config.sh" fn_print_warn "No queryport found using info_config.sh"
fn_script_log_warn "No queryport found using info_config.sh" fn_script_log_warn "No queryport found using info_config.sh"
userconfigfile="${filesdir}" userconfigfile="${filesdir}"
userconfigfile+="/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini" userconfigfile+="/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini"
queryport=$(grep ^QueryPort= ${userconfigfile} | cut -d= -f2 | sed "s/[^[:digit:].*].*//g") queryport=$(grep ^QueryPort= ${userconfigfile} | cut -d= -f2 | sed "s/[^[:digit:].*].*//g")
fi fi
if [ -z "${queryport}" ]; then if [ -z "${queryport}" ]; then
fn_print_warn "No queryport found in the GameUsersettings.ini file" fn_print_warn "No queryport found in the GameUsersettings.ini file"
fn_script_log_warn "No queryport found in the GameUsersettings.ini file" fn_script_log_warn "No queryport found in the GameUsersettings.ini file"
return return
fi fi
if [[ ${#queryport} -gt 0 ]] ; then if [ "${#queryport}" -gt 0 ] ; then
for (( pidcheck=0 ; pidcheck < ${maxpiditer} ; pidcheck++ )) ; do for (( pidcheck=0 ; pidcheck < ${maxpiditer} ; pidcheck++ )) ; do
pid=$(netstat -nap 2>/dev/null | grep ^udp[[:space:]] |\ pid=$(netstat -nap 2>/dev/null | grep ^udp[[:space:]] |\
grep :${queryport}[[:space:]] | rev | awk '{print $1}' |\ grep :${queryport}[[:space:]] | rev | awk '{print $1}' |\
rev | cut -d\/ -f1) rev | cut -d\/ -f1)
# #
# check for a valid pid # check for a valid pid
pid=${pid//[!0-9]/} pid=${pid//[!0-9]/}
let pid+=0 # turns an empty string into a valid number, '0', let pid+=0 # turns an empty string into a valid number, '0',
# and a valid numeric pid remains unchanged. # and a valid numeric pid remains unchanged.
if [[ ${pid} -gt 1 && $pid -le $(cat /proc/sys/kernel/pid_max) ]] ; then if [ "${pid}" -gt 1 && "${pid}" -le $(cat /proc/sys/kernel/pid_max) ]; then
fn_print_dots "Process still bound. Awaiting graceful exit: ${pidcheck}" fn_print_dots "Process still bound. Awaiting graceful exit: ${pidcheck}"
sleep 1 sleep 1
else else
break # Our job is done here break # Our job is done here
fi # end if for pid range check fi # end if for pid range check
done done
if [[ ${pidcheck} -eq ${maxpiditer} ]] ; then if [[ ${pidcheck} -eq ${maxpiditer} ]] ; then
# The process doesn't want to close after 20 seconds. # The process doesn't want to close after 20 seconds.
# kill it hard. # kill it hard.
fn_print_error "Terminating reluctant Ark process: ${pid}" fn_print_error "Terminating reluctant Ark process: ${pid}"
kill -9 $pid kill -9 ${pid}
fi fi
fi # end if for port check fi # end if for port check
} # end of fn_stop_ark } # end of fn_stop_ark
fn_stop_teamspeak3(){ fn_stop_teamspeak3(){
@ -327,11 +325,10 @@ fn_stop_tmux(){
# Remove lockfile # Remove lockfile
rm -f "${rootdir}/${lockselfname}" rm -f "${rootdir}/${lockselfname}"
# ARK doesn't clean up immediately after tmux is killed. # ARK doesn't clean up immediately after tmux is killed.
# Make certain the ports are cleared before continuing. # Make certain the ports are cleared before continuing.
if [ "${gamename}" == "ARK: Survival Evolved" ]; then if [ "${gamename}" == "ARK: Survival Evolved" ]; then
fn_stop_ark fn_stop_ark
echo -en "\n" fi
fi
fn_print_ok_nl "${servername}" fn_print_ok_nl "${servername}"
fn_script_log_pass "Stopped ${servername}" fn_script_log_pass "Stopped ${servername}"
else else

Loading…
Cancel
Save