fn_monitor_query 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. # LGSM fn_monitor_query function
  3. # Author: Daniel Gibbs
  4. # Website: http://gameservermanagers.com
  5. # Version: 311015
  6. # Description: uses gsquery.py to directly query the server.
  7. # Detects if the server has frozen.
  8. local modulename="Monitor"
  9. if [ -f "${rootdir}/gsquery.py" ]; then
  10. if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
  11. gameport=$(grep Port= "${servercfgfullpath}"|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|tr -d '\r'|tr -cd '[:digit:]')
  12. port=$((${gameport} + 1))
  13. elif [ "${engine}" == "spark" ]; then
  14. port=$((${port} + 1))
  15. elif [ "${engine}" == "realvirtuality" ]; then
  16. queryport=$(grep -s steamqueryport= "${servercfgfullpath}"|grep -v //|tr -d '\r'|tr -cd '[:digit:]')
  17. port=${queryport}
  18. elif [ "${engine}" == "unity3d" ]; then
  19. gameport=$(grep ServerPort "${servercfgfullpath}"|tr -cd '[:digit:]')
  20. port=$((${gameport} + 1))
  21. fi
  22. fn_printinfo "Detected gsquery.py"
  23. fn_scriptlog "Detected gsquery.py"
  24. sleep 1
  25. fn_printdots "Querying port: ${ip}:${port} : QUERYING"
  26. fn_scriptlog "Querying port: ${ip}:${port} : QUERYING"
  27. sleep 1
  28. serverquery=$(${rootdir}/gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
  29. exitcode=$?
  30. if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
  31. fn_printfail "Querying port: ${ip}:${port} : ${serverquery}"
  32. fn_scriptlog "Querying port: ${ip}:${port} : ${serverquery}"
  33. sleep 1
  34. echo -en "\n"
  35. if [[ -z "${secondquery}" ]]; then
  36. if [ "${engine}" == "unreal2" ]; then
  37. # unreal 2: Map change can take around 60 seconds
  38. fn_printinfo "Waiting 60 seconds to re-query"
  39. fn_scriptlog "Waiting 60 seconds to re-query"
  40. sleep 60
  41. else
  42. fn_printinfo "Waiting 30 seconds to re-query"
  43. fn_scriptlog "Waiting 30 seconds to re-query"
  44. sleep 30
  45. fi
  46. secondquery=1
  47. fn_monitor_query
  48. fi
  49. if [ "${emailnotification}" = "on" ]; then
  50. fn_details_config
  51. subject="${servicename} Monitor - Starting ${servername}"
  52. failurereason="Failed to query ${servicename}: ${serverquery}"
  53. actiontaken="restarted ${servicename}"
  54. fn_email
  55. fi
  56. fn_restart
  57. exit 1
  58. elif [ "${exitcode}" == "0" ]; then
  59. fn_printok "Querying port: ${ip}:${port} : OK"
  60. fn_scriptlog "Querying port: ${ip}:${port} : OK"
  61. sleep 1
  62. echo -en "\n"
  63. exit
  64. elif [ "${exitcode}" == "126" ]; then
  65. fn_printfail "Querying port: ${ip}:${port} : ERROR: ${rootdir}/gsquery.py: Permission denied"
  66. fn_scriptlog "Querying port: ${ip}:${port} : ERROR: ${rootdir}/gsquery.py: Permission denied"
  67. sleep 1
  68. echo -en "\n"
  69. echo "Attempting to resolve automatically"
  70. chmod +x -v "${rootdir}/gsquery.py"
  71. exitcode=$?
  72. if [ "${exitcode}" == "0" ]; then
  73. fn_monitor_query
  74. else
  75. fn_printfailure "Unable to resolve automatically. Please manually fix permissions.\n"
  76. owner=$(ls -al ${rootdir}/gsquery.py|awk '{ print $3 }')
  77. echo "As user ${owner} or root run the following command."
  78. whoami=$(whoami)
  79. echo -en "\nchown ${whoami}:${whoami} ${rootdir}/gsquery.py\n\n"
  80. exit 1
  81. fi
  82. else
  83. fn_printfail "Querying port: ${ip}:${port} : UNKNOWN ERROR"
  84. fn_scriptlog "Querying port: ${ip}:${port} : UNKNOWN ERROR"
  85. sleep 1
  86. echo -en "\n"
  87. ${rootdir}/gsquery.py -a ${ip} -p ${port} -e ${engine}
  88. exit 1
  89. fi
  90. else
  91. fn_printfailnl "Could not find ${rootdir}/gsquery.py"
  92. fn_scriptlog "Could not find ${rootdir}/gsquery.py"
  93. fi