@ -4,94 +4,91 @@
# Website: http://gameservermanagers.com
# Website: http://gameservermanagers.com
lgsm_version = "271215"
lgsm_version = "271215"
# Description: uses gsquery.py to directly query the server.
# Description: uses gsquery.py to query the server port .
# Detects if the server has frozen.
# Detects if the server has frozen with the proccess still running .
local modulename = "Monitor"
local modulename = "Monitor"
if [ -f " ${ rootdir } /gsquery.py " ] ; then
if [ " ${ engine } " = = "unreal" ] || [ " ${ engine } " = = "unreal2" ] ; then
# Downloads gsquery.py if missing
gameport = $( grep Port = " ${ servercfgfullpath } " | grep -v Master| grep -v LAN| grep -v Proxy| grep -v Listen| tr -d '\r' | tr -cd '[:digit:]' )
if [ ! -f " ${ functionsdir } /gsquery.py " ] ; then
port = $(( ${ gameport } + 1 ))
fn_fetch_file_github "functions" "gsquery.py" " ${ functionsdir } " "executecmd" "norun" "noforce"
elif [ " ${ engine } " = = "spark" ] ; then
fi
port = $(( ${ port } + 1 ))
elif [ " ${ engine } " = = "realvirtuality" ] ; then
info_config.sh
queryport = $( grep -s steamqueryport = " ${ servercfgfullpath } " | grep -v //| tr -d '\r' | tr -cd '[:digit:]' )
port = ${ queryport }
if [ " ${ engine } " = = "unreal" ] || [ " ${ engine } " = = "unreal2" ] ; then
elif [ " ${ gamename } " = = "7 Days To Die" ] ; then
port = $(( ${ port } + 1 ))
gameport = $( grep ServerPort " ${ servercfgfullpath } " | tr -cd '[:digit:]' )
elif [ " ${ engine } " = = "spark" ] ; then
port = $(( ${ gameport } + 1 ))
port = $(( ${ port } + 1 ))
elif [ " ${ gamename } " = = "Hurtworld" ] ; then
fi
gameport = " ${ port } "
port = " ${ queryport } "
if [ -z " ${ queryport } " ] ; then
fi
port = " ${ queryport } "
fn_printinfo "Detected gsquery.py"
fi
fn_scriptlog "Detected gsquery.py"
sleep 1
fn_printdots " Querying port: ${ ip } : ${ port } : QUERYING "
fn_printinfo "Querying port: gsquery.py enabled"
fn_scriptlog " Querying port: ${ ip } : ${ port } : QUERYING "
fn_scriptlog "gsquery.py enabled"
sleep 1
sleep 1
serverquery = $( " ${ rootdir } /gsquery.py " -a ${ ip } -p ${ port } -e ${ engine } 2>& 1)
fn_printdots " Querying port: ${ ip } : ${ port } : 0/1 : "
fn_printqueryingeol
fn_scriptlog " Querying port: ${ ip } : ${ port } : 1 : QUERYING "
sleep 1
# Will query up to 4 times every 15 seconds.
# Servers changing map can return a failure.
# Will Wait up to 60 seconds to confirm server is down giving server time to change map.
queryattempt = 0
totalseconds = 0
for i in { 1..4} ; do
gsquerycmd = $( " ${ functionsdir } " /gsquery.py -a ${ ip } -p 1 -e ${ engine } 2>& 1)
exitcode = $?
exitcode = $?
if [ " ${ exitcode } " = = "1" ] || [ " ${ exitcode } " = = "2" ] || [ " ${ exitcode } " = = "3" ] || [ " ${ exitcode } " = = "4" ] ; then
fn_printfail " Querying port: ${ ip } : ${ port } : ${ serverquery } "
if [ " ${ exitcode } " = = "0" ] ; then
fn_scriptlog " Querying port: ${ ip } : ${ port } : ${ serverquery } "
# Server OK
fn_printok " Querying port: ${ ip } : ${ port } : "
fn_printokeol
fn_scriptlog " Querying port: ${ ip } : ${ port } : OK "
sleep 1
sleep 1
echo -en "\n"
exit
if [ -z " ${ secondquery } " ] ; then
else
if [ " ${ engine } " = = "unreal2" ] ; then
# Server failed query
# unreal 2: Map change can take around 60 seconds
queryattempt = $(( queryattempt + 1 ))
fn_printinfo "Waiting 60 seconds to re-query"
fn_scriptlog " Querying port: ${ ip } : ${ port } : ${ totalseconds } / ${ queryattempt } : ${ gsquerycmd } "
fn_scriptlog "Waiting 60 seconds to re-query"
seconds = 0
sleep 60
# Seconds counter
else
while [ true ] ; do
fn_printinfo "Waiting 30 seconds to re-query"
fn_printfail " Querying port: ${ ip } : ${ port } : ${ totalseconds } / ${ queryattempt } : \e[0;31m ${ gsquerycmd } \e[0m "
fn_scriptlog "Waiting 30 seconds to re-query"
seconds = $(( seconds + 1 ))
sleep 30
totalseconds = $(( totalseconds + 1 ))
fi
sleep 1
secondquery = 1
if [ " ${ seconds } " = = "15" ] ; then
monitor_gsquery.sh
fn_printdots " Querying port: ${ ip } : ${ port } : ${ totalseconds } / ${ queryattempt } : "
fi
fn_printqueryingeol
fn_scriptlog " Querying port: ${ ip } : ${ port } : ${ queryattempt } : QUERYING "
sleep 1
break
fi
done
fi
if [ " ${ queryattempt } " = = "4" ] ; then
# Server failed query 4 times confirmed failure
fn_printfail " Querying port: ${ ip } : ${ port } : "
fn_printfaileol
fn_scriptlog " Querying port: ${ ip } : ${ port } : ${ gsquerycmd } "
fn_scriptlog " Querying port: ${ ip } : ${ port } : FAIL "
sleep 1
# Send email notification if enabled
if [ " ${ emailnotification } " = "on" ] ; then
if [ " ${ emailnotification } " = "on" ] ; then
info_config.sh
info_config.sh
subject = " ${ servicename } Monitor - Starting ${ servername } "
subject = " ${ servicename } Monitor - Starting ${ servername } "
failurereason = " Failed to query ${ servicename } : ${ serverquery } "
failurereason = " Failed to query ${ servicename } : ${ g squerycmd } "
actiontaken = " restarted ${ servicename } "
actiontaken = " restarted ${ servicename } "
email.sh
email.sh
fi
fi
fn_restart
fn_restart
exit 1
fi
elif [ " ${ exitcode } " = = "0" ] ; then
done
fn_printok " Querying port: ${ ip } : ${ port } : OK "
fn_scriptlog " Querying port: ${ ip } : ${ port } : OK "
sleep 1
echo -en "\n"
exit
elif [ " ${ exitcode } " = = "126" ] ; then
fn_printfail " Querying port: ${ ip } : ${ port } : ERROR: ${ rootdir } /gsquery.py: Permission denied "
fn_scriptlog " Querying port: ${ ip } : ${ port } : ERROR: ${ rootdir } /gsquery.py: Permission denied "
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
chmod +x -v " ${ rootdir } /gsquery.py "
if [ $? -eq 0 ] ; then
monitor_gsquery.sh
else
fn_printfailure "Unable to resolve automatically. Please manually fix permissions.\n"
owner = $( ls -al ${ rootdir } /gsquery.py| awk '{ print $3 }' )
echo " As user ${ owner } or root run the following command. "
whoami = $( whoami)
echo -en " \nchown ${ whoami } : ${ whoami } ${ rootdir } /gsquery.py\n\n "
exit 1
fi
else
fn_printfail " Querying port: ${ ip } : ${ port } : UNKNOWN ERROR "
fn_scriptlog " Querying port: ${ ip } : ${ port } : UNKNOWN ERROR "
sleep 1
echo -en "\n"
${ rootdir } /gsquery.py -a ${ ip } -p ${ port } -e ${ engine }
exit 1
fi
else
fn_printfailnl " Could not find ${ rootdir } /gsquery.py "
fn_scriptlog " Could not find ${ rootdir } /gsquery.py "
fi