command_monitor.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/bash
  2. # LinuxGSM command_monitor.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://gameservermanagers.com
  6. # Description: Monitors server by checking for running processes.
  7. # then passes to monitor_gsquery.sh.
  8. local commandname="MONITOR"
  9. local commandaction="Monitor"
  10. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  11. fn_monitor_check_lockfile(){
  12. # Monitor does not run it lockfile is not found
  13. if [ ! -f "${rootdir}/${lockselfname}" ]; then
  14. fn_print_error_nl "Disabled: No lockfile found"
  15. fn_script_log_error "Disabled: No lockfile found"
  16. echo " * To enable monitor run ./${selfname} start"
  17. core_exit.sh
  18. fi
  19. }
  20. fn_monitor_check_update(){
  21. # Monitor will not check if update is running.
  22. if [ "$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)" != "0" ]; then
  23. fn_print_error_nl "SteamCMD is currently checking for updates"
  24. fn_script_log_error "SteamCMD is currently checking for updates"
  25. sleep 1
  26. core_exit.sh
  27. fi
  28. }
  29. fn_monitor_msg_checking(){
  30. fn_print_dots "Checking session: "
  31. fn_print_checking_eol
  32. fn_script_log_info "Checking session: CHECKING"
  33. sleep 1
  34. }
  35. fn_monitor_teamspeak3(){
  36. if [ "${status}" != "0" ]; then
  37. fn_print_ok "Checking session: "
  38. fn_print_ok_eol_nl
  39. fn_script_log_pass "Checking session: OK"
  40. else
  41. fn_print_error "Checking session: ${ts3error}: "
  42. fn_print_fail_eol_nl
  43. fn_script_log_error "Checking session: ${ts3error}: FAIL"
  44. failurereason="${ts3error}"
  45. alert="restart"
  46. alert.sh
  47. fn_script_log_info "Monitor is starting ${servername}"
  48. sleep 1
  49. command_restart.sh
  50. fi
  51. }
  52. fn_monitor_mumble(){
  53. if [ "${status}" != "0" ]; then
  54. fn_print_ok "Checking session: "
  55. fn_print_ok_eol_nl
  56. fn_script_log_pass "Checking session: OK"
  57. else
  58. fn_print_error "Checking session: Not listening to port ${port}"
  59. fn_print_fail_eol_nl
  60. fn_script_log_error "Checking session: Not listening to port ${port}"
  61. failurereason="Checking session: Not listening to port ${port}"
  62. alert="restart"
  63. alert.sh
  64. fn_script_log_info "Monitor is starting ${servername}"
  65. sleep 1
  66. command_restart.sh
  67. fi
  68. }
  69. fn_monitor_tmux(){
  70. # checks that tmux session is running
  71. if [ "${status}" != "0" ]; then
  72. fn_print_ok "Checking session: "
  73. fn_print_ok_eol_nl
  74. fn_script_log_pass "Checking session: OK"
  75. # runs gsquery check on game with specific engines.
  76. local allowed_engines_array=( avalanche goldsource idtech3 idtech3_ql iw2.0 iw3.0 quake refractor realvirtuality source spark unity3d unreal unreal2 )
  77. for allowed_engine in "${allowed_engines_array[@]}"
  78. do
  79. if [ "${allowed_engine}" == "${engine}" ]; then
  80. monitor_gsquery.sh
  81. fi
  82. done
  83. else
  84. fn_print_error "Checking session: "
  85. fn_print_fail_eol_nl
  86. fn_script_log_error "Checking session: FAIL"
  87. alert="restart"
  88. alert.sh
  89. fn_script_log_info "Monitor is starting ${servername}"
  90. sleep 1
  91. command_restart.sh
  92. fi
  93. }
  94. monitorflag=1
  95. fn_print_dots "${servername}"
  96. sleep 1
  97. check.sh
  98. logs.sh
  99. info_config.sh
  100. fn_monitor_check_lockfile
  101. fn_monitor_check_update
  102. fn_monitor_msg_checking
  103. if [ "${gamename}" == "TeamSpeak 3" ]; then
  104. fn_monitor_teamspeak3
  105. elif [ "${gamename}" == "Mumble" ]; then
  106. fn_monitor_mumble
  107. else
  108. fn_monitor_tmux
  109. fi
  110. core_exit.sh