Explorar o código

Merge pull request #832 from dgibbs64/development

Ark Restart fixes
Daniel Gibbs %!s(int64=10) %!d(string=hai) anos
pai
achega
17ae19eef1
Modificáronse 2 ficheiros con 49 adicións e 4 borrados
  1. 48 3
      lgsm/functions/command_stop.sh
  2. 1 1
      lgsm/functions/core_functions.sh

+ 48 - 3
lgsm/functions/command_stop.sh

@@ -156,9 +156,48 @@ 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"
+                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 < ${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
+} # end of fn_stop_ark
+
 fn_stop_teamspeak3(){
 	fn_print_dots "${servername}"
 	fn_scriptlog "${servername}"
@@ -187,6 +226,12 @@ fn_stop_tmux(){
 	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
@@ -204,7 +249,7 @@ fn_stop_pre_check(){
 			fn_scriptlog "${servername} is already stopped"
 		else
 			fn_stop_teamspeak3
-		fi      
+		fi
 	else
 		check_status.sh
 		if [ "${status}" == "0" ]; then
@@ -221,4 +266,4 @@ info_config.sh
 fn_print_dots "${servername}"
 fn_scriptlog "${servername}"
 sleep 1
-fn_stop_pre_check
+fn_stop_pre_check

+ 1 - 1
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(){