lgsm local mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

78 lines
2.8 KiB

#!/bin/bash
# LGSM fn_serverquery function
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 081214
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= "${systemdir}/${ini}"|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g'|tr -d '\r')
port=$((${gameport} + 1))
elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1))
elif [ "${engine}" == "realvirtuality" ]; then
port=${queryport}
fi
fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
fn_scriptlog "Detected gsquery.py"
sleep 1
fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
sleep 1
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
sleep 1
echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then
fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30
secondquery=1
fn_serverquery
fi
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="Failed to query ${servicename}: ${serverquery}"
actiontaken="restarted ${servicename}"
fn_emailnotification
fi
fn_restartserver
exit
elif [ "${exitcode}" == "0" ]; then
fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n"
exit
elif [ "${exitcode}" == "126" ]; then
fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
chmod +x -v gsquery.py
exitcode=$?
if [ "${exitcode}" == "0" ]; then
fn_serverquery
else
echo -en "\nUnable to resolve automatically. Please manually fix permissions\n"
owner=$(ls -al gsquery.py|awk '{ print $3 }')
echo "As user ${owner} or root run the following command"
whoami=$(whoami)
echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n"
exit
fi
else
fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
fi
fi