command_monitor.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 processes.
  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_tmux(){
  52. # checks that tmux session is running
  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. # runs gsquery check on game with specific engines.
  58. local allowed_engines_array=( avalanche goldsource realvirtuality source spark unity3d unreal unreal2 )
  59. for allowed_engine in "${allowed_engines_array[@]}"
  60. do
  61. if [ "${allowed_engine}" == "${engine}" ]; then
  62. monitor_gsquery.sh
  63. fi
  64. done
  65. else
  66. fn_print_error "Checking session: "
  67. fn_print_fail_eol_nl
  68. fn_script_log_error "Checking session: FAIL"
  69. alert="restart"
  70. alert.sh
  71. fn_script_log_info "Monitor is starting ${servername}"
  72. sleep 1
  73. command_restart.sh
  74. fi
  75. }
  76. fn_print_dots "${servername}"
  77. sleep 1
  78. check.sh
  79. logs.sh
  80. info_config.sh
  81. fn_monitor_check_lockfile
  82. fn_monitor_check_update
  83. fn_monitor_msg_checking
  84. if [ "${gamename}" == "Teamspeak 3" ]; then
  85. fn_monitor_teamspeak3
  86. else
  87. fn_monitor_tmux
  88. fi
  89. core_exit.sh