command_monitor.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 modulename="Monitor"
  8. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  9. fn_monitor_check_lockfile(){
  10. # Monitor does not run it lockfile is not found
  11. if [ ! -f "${rootdir}/${lockselfname}" ]; then
  12. fn_print_info_nl "Disabled: No lock file found"
  13. fn_script_log_info "Disabled: No lock file found"
  14. echo " * To enable monitor run ./${selfname} start"
  15. core_exit.sh
  16. fi
  17. }
  18. fn_monitor_check_update(){
  19. # Monitor will not check if update is running.
  20. if [ "$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)" != "0" ]; then
  21. fn_print_info_nl "SteamCMD is currently checking for updates"
  22. fn_script_log_info "SteamCMD is currently checking for updates"
  23. sleep 1
  24. core_exit.sh
  25. fi
  26. }
  27. fn_monitor_msg_checking(){
  28. fn_print_dots "Checking session: "
  29. fn_print_checking_eol
  30. fn_script_log_info "Checking session: CHECKING"
  31. sleep 1
  32. }
  33. fn_monitor_teamspeak3(){
  34. if [ "${status}" != "0" ]; then
  35. fn_print_ok "Checking session: "
  36. fn_print_ok_eol_nl
  37. fn_script_log_pass "Checking session: OK"
  38. else
  39. fn_print_fail "Checking session: ${ts3error}: "
  40. fn_print_fail_eol_nl
  41. fn_script_log_error "Checking session: ${ts3error}: FAIL"
  42. failurereason="${ts3error}"
  43. alert="restart"
  44. alert.sh
  45. fn_script_log_info "Monitor is starting ${servername}"
  46. sleep 1
  47. fn_restart
  48. fi
  49. }
  50. fn_monitor_tmux(){
  51. # checks that tmux session is running
  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. # runs gsquery check on game with specific engines.
  57. local allowed_engines_array=( avalanche goldsource realvirtuality source spark unity3d unreal unreal2 )
  58. for allowed_engine in "${allowed_engines_array[@]}"
  59. do
  60. if [ "${allowed_engine}" == "${engine}" ]; then
  61. monitor_gsquery.sh
  62. fi
  63. done
  64. else
  65. fn_print_fail "Checking session: "
  66. fn_print_fail_eol_nl
  67. fn_script_log_error "Checking session: FAIL"
  68. alert="restart"
  69. alert.sh
  70. fn_script_log_info "Monitor is starting ${servername}"
  71. sleep 1
  72. command_start.sh
  73. fi
  74. }
  75. check.sh
  76. logs.sh
  77. info_config.sh
  78. fn_print_dots "${servername}"
  79. sleep 1
  80. fn_monitor_check_lockfile
  81. fn_monitor_check_update
  82. fn_monitor_msg_checking
  83. if [ "${gamename}" == "Teamspeak 3" ]; then
  84. fn_monitor_teamspeak3
  85. else
  86. fn_monitor_tmux
  87. fi
  88. core_exit.sh