Browse Source

Added error checking for SDTD shutdown

pull/351/head
Daniel Gibbs 10 years ago
parent
commit
c081adbe22
  1. 124
      functions/fn_stop

124
functions/fn_stop

@ -8,6 +8,27 @@
local modulename="Stopping" local modulename="Stopping"
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_teamspeak3(){ fn_stop_teamspeak3(){
fn_check_root fn_check_root
fn_check_systemdir fn_check_systemdir
@ -16,12 +37,12 @@ fn_scriptlog "${servername}"
sleep 1 sleep 1
fn_check_ts3status fn_check_ts3status
if [ "${ts3status}" = "No server running (ts3server.pid is missing)" ];then if [ "${ts3status}" = "No server running (ts3server.pid is missing)" ];then
fn_printfail "${servername} is already stopped" fn_printfail "${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
${filesdir}/ts3server_startscript.sh stop inifile=${ini} > /dev/null 2>&1 ${filesdir}/ts3server_startscript.sh stop inifile=${ini} > /dev/null 2>&1
fn_printok "${servername}" fn_printok "${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
# Remove lock file # Remove lock file
rm -f "${rootdir}/${lockselfname}" rm -f "${rootdir}/${lockselfname}"
@ -44,45 +65,76 @@ if [ "${gamename}" == "7 Days To Die" ] ; then
fn_printdots "Attempting graceful shutdown via telnet" fn_printdots "Attempting graceful shutdown via telnet"
fn_scriptlog "Attempting graceful shutdown via telnet" fn_scriptlog "Attempting graceful shutdown via telnet"
sleep 1 sleep 1
telnetip=127.0.0.1 telnetip=127.0.0.1
sdtdshutdown=$( expect -c ' sdtd_telnet
proc abort {} {
puts "Timeout or EOF\n" # If failed using localhost will use servers ip
exit 1 refused=$(echo -en "\n ${sdtdshutdown}"| grep "Timeout or EOF")
} if [ -n "${refused}" ]; then
spawn telnet '"${telnetip}"' '"${telnetport}"' fn_check_ip
expect { telnetip=${ip}
"password:" { send "'"${telnetpass}"'\r" } fn_printwarn "Attempting graceful shutdown via telnet: localhost failed"
default abort fn_scriptlog "Warning! Attempting graceful shutdown failed using localhost"
} sleep 5
expect { echo -en "\n"
"session." { send "shutdown\r" } fn_printdots "Attempting graceful shutdown via telnet: using ${telnetip}"
default abort fn_scriptlog "Attempting graceful shutdown via telnet using ${telnetip}"
} sdtd_telnet
expect { eof } sleep 1
puts "Completed.\n" 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 ${sdtdshutdown}"
fn_printok "Attempting graceful shutdown via telnet" echo -en "\n\n"
fn_scriptlog "Attempting graceful shutdown succeeded"
sleep 1 sleep 1
fn_printdots "${servername}" fn_printdots "${servername}"
fn_scriptlog "${servername}" fn_scriptlog "${servername}"
sleep 1 sleep 5
fi pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") if [ "${pid}" == "0" ]; then
if [ "${pid}" == "0" ]; then fn_printok "${servername} is already stopped using graceful shutdown"
fn_printfail "${servername} is already stopped" fn_scriptlog "${servername} is already stopped using graceful shutdown"
fn_scriptlog "${servername} is already stopped" else
tmux kill-session -t ${servicename}
fn_printok "${servername}"
fn_scriptlog "Stopped ${servername}"
fi
else else
tmux kill-session -t ${servicename} pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
fn_printok "${servername}" if [ "${pid}" == "0" ]; then
fn_scriptlog "Stopped ${servername}" 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
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
Loading…
Cancel
Save