command_monitor.sh 3.1 KB

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