command_monitor.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. # LinuxGSM command_monitor.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://linuxgsm.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=( avalanche2.0 avalanche3.0 goldsource idtech2 idtech3 idtech3_ql iw2.0 iw3.0 madness quake refractor realvirtuality source spark starbound unity3d unreal unreal2 )
  77. for allowed_engine in "${allowed_engines_array[@]}"
  78. do
  79. if [ "${allowed_engine}" == "starbound" ]; then
  80. info_config.sh
  81. if [ "${queryenabled}" == "true" ]; then
  82. monitor_gsquery.sh
  83. fi
  84. elif [ "${allowed_engine}" == "${engine}" ]; then
  85. monitor_gsquery.sh
  86. fi
  87. done
  88. else
  89. fn_print_error "Checking session: "
  90. fn_print_fail_eol_nl
  91. fn_script_log_error "Checking session: FAIL"
  92. alert="restart"
  93. alert.sh
  94. fn_script_log_info "Monitor is starting ${servername}"
  95. sleep 1
  96. command_restart.sh
  97. fi
  98. }
  99. monitorflag=1
  100. fn_print_dots "${servername}"
  101. sleep 1
  102. check.sh
  103. logs.sh
  104. info_config.sh
  105. fn_monitor_check_lockfile
  106. fn_monitor_check_update
  107. fn_monitor_msg_checking
  108. if [ "${gamename}" == "TeamSpeak 3" ]; then
  109. fn_monitor_teamspeak3
  110. elif [ "${gamename}" == "Mumble" ]; then
  111. fn_monitor_mumble
  112. else
  113. fn_monitor_tmux
  114. fi
  115. core_exit.sh