4
0

monitor_gsquery.sh 2.5 KB

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