monitor_gsquery.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/bash
  2. # LinuxGSM monitor_gsquery.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Uses gsquery.py to query the server port.
  6. # Detects if the server has frozen with the process still running.
  7. local commandname="MONITOR"
  8. local commandaction="Monitor"
  9. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. if [ "${gsquery}" == "yes" ]; then
  11. # Downloads gsquery.py if missing
  12. if [ ! -f "${functionsdir}/gsquery.py" ]; then
  13. fn_fetch_file_github "lgsm/functions" "gsquery.py" "${functionsdir}" "chmodx" "norun" "noforce" "nomd5"
  14. fi
  15. info_config.sh
  16. if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
  17. port=$((port + 1))
  18. elif [ "${engine}" == "realvirtuality" ]; then
  19. port=$((port + 1))
  20. elif [ "${engine}" == "spark" ]; then
  21. port=$((port + 1))
  22. elif [ "${engine}" == "idtech3_ql" ]; then
  23. engine="quakelive"
  24. fi
  25. if [ -n "${queryport}" ]; then
  26. port="${queryport}"
  27. fi
  28. fn_print_info "Querying port: gsquery.py enabled"
  29. fn_script_log_info "Querying port: gsquery.py enabled"
  30. sleep 1
  31. # Will query up to 4 times every 15 seconds.
  32. # Servers changing map can return a failure.
  33. # Will Wait up to 60 seconds to confirm server is down giving server time to change map.
  34. totalseconds=0
  35. for queryattempt in {1..5}; do
  36. fn_print_dots "Querying port: ${ip}:${port} : ${totalseconds}/${queryattempt} : "
  37. fn_print_querying_eol
  38. fn_script_log_info "Querying port: ${ip}:${port} : ${queryattempt} : QUERYING"
  39. gsquerycmd=$("${functionsdir}"/gsquery.py -a "${ip}" -p "${port}" -e "${engine}" 2>&1)
  40. exitcode=$?
  41. sleep 1
  42. if [ "${exitcode}" == "0" ]; then
  43. # Server OK
  44. fn_print_ok "Querying port: ${ip}:${port} : ${queryattempt} : "
  45. fn_print_ok_eol_nl
  46. fn_script_log_pass "Querying port: ${ip}:${port} : ${queryattempt} : OK"
  47. exitcode=0
  48. break
  49. else
  50. # Server failed query
  51. fn_script_log_info "Querying port: ${ip}:${port} : ${queryattempt} : ${gsquerycmd}"
  52. if [ "${queryattempt}" == "5" ]; then
  53. # Server failed query 4 times confirmed failure
  54. fn_print_fail "Querying port: ${ip}:${port} : ${totalseconds}/${queryattempt} : "
  55. fn_print_fail_eol_nl
  56. fn_script_log_error "Querying port: ${ip}:${port} : ${queryattempt} : FAIL"
  57. sleep 1
  58. # Send alert if enabled
  59. alert="restartquery"
  60. alert.sh
  61. command_restart.sh
  62. break
  63. fi
  64. # Seconds counter
  65. for seconds in {1..15}; do
  66. fn_print_fail "Querying port: ${ip}:${port} : ${totalseconds}/${queryattempt} : ${red}${gsquerycmd}${default}"
  67. totalseconds=$((totalseconds + 1))
  68. sleep 1
  69. if [ "${seconds}" == "15" ]; then
  70. break
  71. fi
  72. done
  73. fi
  74. done
  75. fi
  76. core_exit.sh