Browse Source

Fixed looping issues

pull/743/head
Daniel Gibbs 9 years ago
parent
commit
9f5425bda7
  1. 77
      functions/monitor_gsquery.sh

77
functions/monitor_gsquery.sh

@ -2,13 +2,20 @@
# LGSM monitor_gsquery.sh function # LGSM monitor_gsquery.sh function
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://gameservermanagers.com # Website: http://gameservermanagers.com
lgsm_version="271215" lgsm_version="270216"
# Description: uses gsquery.py to query the server port. # Description: uses gsquery.py to query the server port.
# Detects if the server has frozen with the proccess still running. # Detects if the server has frozen with the proccess still running.
local modulename="Monitor" local modulename="Monitor"
# Forces legecy servers to use gsquery as vat gsquery is not present in legecy
if [ -z "${gsquery}" ]; then
gsquery="yes"
fi
if [ "${gsquery}" == "yes" ]; then
# Downloads gsquery.py if missing # Downloads gsquery.py if missing
if [ ! -f "${functionsdir}/gsquery.py" ]; then if [ ! -f "${functionsdir}/gsquery.py" ]; then
fn_fetch_file_github "functions" "gsquery.py" "${functionsdir}" "executecmd" "norun" "noforce" "nomd5" fn_fetch_file_github "functions" "gsquery.py" "${functionsdir}" "executecmd" "norun" "noforce" "nomd5"
@ -17,78 +24,70 @@ fi
info_config.sh info_config.sh
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
port=$((${port} + 1)) port=$((port + 1))
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((port + 1))
fi fi
if [ -z "${queryport}" ]; then if [ -z "${queryport}" ]; then
port="${queryport}" port="${queryport}"
fi fi
queryattempt=1
totalseconds=0
fn_print_info "Querying port: gsquery.py enabled" fn_print_info "Querying port: gsquery.py enabled"
fn_scriptlog "gsquery.py enabled" fn_scriptlog "Querying port: gsquery.py enabled"
sleep 1
fn_print_dots "Querying port: ${ip}:${port} :${totalseconds}/${queryattempt} : "
fn_print_querying_eol
fn_scriptlog "Querying port: ${ip}:${port} : ${queryattempt} : QUERYING"
sleep 1 sleep 1
# Will query up to 4 times every 15 seconds. # Will query up to 4 times every 15 seconds.
# Servers changing map can return a failure. # Servers changing map can return a failure.
# Will Wait up to 60 seconds to confirm server is down giving server time to change map. # Will Wait up to 60 seconds to confirm server is down giving server time to change map.
totalseconds=0
for queryattempt in {1..5}; do
fn_print_dots "Querying port: ${ip}:${port} : ${totalseconds}/${queryattempt} : "
fn_print_querying_eol
fn_scriptlog "Querying port: ${ip}:${port} : ${queryattempt} : QUERYING"
for i in {1..4}; do gsquerycmd=$("${functionsdir}"/gsquery.py -a "${ip}" -p 1 -e "${engine}" 2>&1)
gsquerycmd=$("${functionsdir}"/gsquery.py -a ${ip} -p 1 -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "0" ]; then if [ "${exitcode}" == "0" ]; then
# Server OK # Server OK
fn_print_ok "Querying port: ${ip}:${port} : " fn_print_ok "Querying port: ${ip}:${port} : ${queryattempt} : "
fn_print_ok_eol fn_print_ok_eol
fn_scriptlog "Querying port: ${ip}:${port} : OK" fn_scriptlog "Querying port: ${ip}:${port} : ${queryattempt} : OK"
sleep 1 sleep 1
exit exit
else else
# Server failed query # Server failed query
fn_scriptlog "Querying port: ${ip}:${port} : ${queryattempt} : ${gsquerycmd}" fn_scriptlog "Querying port: ${ip}:${port} : ${queryattempt} : ${gsquerycmd}"
seconds=0
# Seconds counter
while [ true ]; do
fn_print_fail "Querying port: ${ip}:${port} : ${totalseconds}/${queryattempt} : \e[0;31m${gsquerycmd}\e[0m"
seconds=$((seconds + 1))
totalseconds=$((totalseconds + 1))
sleep 1
if [ "${seconds}" == "15" ]; then
queryattempt=$((queryattempt + 1))
fn_print_dots "Querying port: ${ip}:${port} : ${totalseconds}/${queryattempt} : "
fn_print_querying_eol
fn_scriptlog "Querying port: ${ip}:${port} : ${queryattempt} : QUERYING"
sleep 1
break
fi
done
fi
if [ "${queryattempt}" == "4" ]; then if [ "${queryattempt}" == "5" ]; then
# Server failed query 4 times confirmed failure # Server failed query 4 times confirmed failure
fn_print_fail "Querying port: ${ip}:${port} : " fn_print_fail "Querying port: ${ip}:${port} : ${totalseconds}/${queryattempt} : "
fn_print_fail_eol fn_print_fail_eol_nl
fn_scriptlog "Querying port: ${ip}:${port} : ${gsquerycmd}" fn_scriptlog "Querying port: ${ip}:${port} : ${queryattempt} : FAIL"
fn_scriptlog "Querying port: ${ip}:${port} : FAIL"
sleep 1 sleep 1
# Send email notification if enabled # Send email notification if enabled
if [ "${emailnotification}" = "on" ]; then if [ "${emailnotification}" == "on" ]; then
info_config.sh
subject="${servicename} Monitor - Starting ${servername}" subject="${servicename} Monitor - Starting ${servername}"
failurereason="Failed to query ${servicename}: ${gsquerycmd}" failurereason="Failed to query ${servicename}: ${gsquerycmd}"
actiontaken="restarted ${servicename}" actiontaken="restarted ${servicename}"
email.sh email.sh
fi fi
fn_restart fn_restart
break
fi
# Seconds counter
for seconds in {1..15}; do
fn_print_fail "Querying port: ${ip}:${port} : ${totalseconds}/${queryattempt} : \e[0;31m${gsquerycmd}\e[0m"
totalseconds=$((totalseconds + 1))
sleep 1
if [ "${seconds}" == "15" ]; then
break
fi fi
done done
fi
done
fi
Loading…
Cancel
Save