4
0
Эх сурвалжийг харах

Update fn_stop

Modified stop function to allow for graceful shutdown of a 7 Days To Die server.  The file will still work for other game servers as it checks for the game name to be "7 Days To Die" as set in the sdtdserver script file and it also uses the new telnet variables I added to the sdtdserver script.
If not being run for 7 Days To Die, it reverts to the previous stop method of killing the server process.
chriskoepf 11 жил өмнө
parent
commit
d27f30c498
1 өөрчлөгдсөн 35 нэмэгдсэн , 13 устгасан
  1. 35 13
      functions/fn_stop

+ 35 - 13
functions/fn_stop

@@ -37,23 +37,45 @@ fn_printdots "${servername}"
 fn_scriptlog "${servername}"
 fn_scriptlog "${servername}"
 sleep 1
 sleep 1
 fn_check_tmux
 fn_check_tmux
-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"
+
+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..
+
+                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"
+                ')
+                echo -en "\n ${sdtdshutdown}"
+                fn_printok "${servername}"
+                fn_scriptlog "Performmed graceful shutdown of ${servername}"
 else
 else
-	tmux kill-session -t ${servicename}
-	fn_printok "${servername}"
-	fn_scriptlog "Stopped ${servername}"
+    	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
+            	tmux kill-session -t ${servicename}
+                fn_printok "${servername}"
+                fn_scriptlog "Stopped ${servername}"
+        fi
 fi
 fi
-# Remove lock file
-rm -f "${rootdir}/${lockselfname}"
-sleep 1
-echo -en "\n"
-}
 
 
 if [ "${gamename}" == "Teamspeak 3" ]; then
 if [ "${gamename}" == "Teamspeak 3" ]; then
 	fn_stop_teamspeak3
 	fn_stop_teamspeak3
 else
 else
 	fn_stop_tmux
 	fn_stop_tmux
-fi
+fi