|
|
@ -8,6 +8,27 @@ |
|
|
|
|
|
|
|
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_check_root |
|
|
|
fn_check_systemdir |
|
|
@ -44,32 +65,60 @@ 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 |
|
|
|
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}" |
|
|
|
sdtd_telnet |
|
|
|
|
|
|
|
# If failed using localhost will use servers ip |
|
|
|
refused=$(echo -en "\n ${sdtdshutdown}"| grep "Timeout or EOF") |
|
|
|
if [ -n "${refused}" ]; then |
|
|
|
fn_check_ip |
|
|
|
telnetip=${ip} |
|
|
|
fn_printwarn "Attempting graceful shutdown via telnet: localhost failed" |
|
|
|
fn_scriptlog "Warning! Attempting graceful shutdown failed using localhost" |
|
|
|
sleep 5 |
|
|
|
echo -en "\n" |
|
|
|
fn_printdots "Attempting graceful shutdown via telnet: using ${telnetip}" |
|
|
|
fn_scriptlog "Attempting graceful shutdown via telnet using ${telnetip}" |
|
|
|
sdtd_telnet |
|
|
|
sleep 1 |
|
|
|
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\n" |
|
|
|
sleep 1 |
|
|
|
fn_printdots "${servername}" |
|
|
|
fn_scriptlog "${servername}" |
|
|
|
sleep 1 |
|
|
|
sleep 5 |
|
|
|
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") |
|
|
|
if [ "${pid}" == "0" ]; then |
|
|
|
fn_printok "${servername} is already stopped using graceful shutdown" |
|
|
|
fn_scriptlog "${servername} is already stopped using graceful shutdown" |
|
|
|
else |
|
|
|
tmux kill-session -t ${servicename} |
|
|
|
fn_printok "${servername}" |
|
|
|
fn_scriptlog "Stopped ${servername}" |
|
|
|
fi |
|
|
|
|
|
|
|
else |
|
|
|
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") |
|
|
|
if [ "${pid}" == "0" ]; then |
|
|
|
fn_printfail "${servername} is already stopped" |
|
|
@ -79,6 +128,9 @@ else |
|
|
|
fn_printok "${servername}" |
|
|
|
fn_scriptlog "Stopped ${servername}" |
|
|
|
fi |
|
|
|
fi |
|
|
|
sleep 1 |
|
|
|
echo -en "\n" |
|
|
|
} |
|
|
|
|
|
|
|
if [ "${gamename}" == "Teamspeak 3" ]; then |
|
|
|