Jelajahi Sumber

Graceful quit for source and goldsrc added

fn_stop will attempt to shutdown source and goldsource gracefully before
using tmux shutdown.
Daniel Gibbs 10 tahun lalu
induk
melakukan
d39fc9f01c
1 mengubah file dengan 26 tambahan dan 8 penghapusan
  1. 26 8
      functions/fn_stop

+ 26 - 8
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