command_monitor.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. # LGSM command_monitor.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. lgsm_version="210516"
  6. # Description: Monitors server by checking for running proccesses
  7. # then passes to monitor_gsquery.sh.
  8. local modulename="Monitor"
  9. 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_info_nl "Disabled: No lock file found"
  14. fn_script_log_info "Disabled: No lock file found"
  15. echo " * To enable monitor run ./${selfname} start"
  16. exit 1
  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_info_nl "SteamCMD is currently checking for updates"
  23. fn_script_log_info "SteamCMD is currently checking for updates"
  24. sleep 1
  25. exit
  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. exit
  40. else
  41. fn_print_fail "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. fi
  48. fn_script_log_info "Monitor is starting ${servername}"
  49. sleep 1
  50. fn_restart
  51. }
  52. fn_monitor_tmux(){
  53. # checks that tmux session is running
  54. if [ "${status}" != "0" ]; then
  55. fn_print_ok "Checking session: "
  56. fn_print_ok_eol_nl
  57. fn_script_log_pass "Checking session: OK"
  58. # runs gsquery check on game with specific engines.
  59. local allowed_engines_array=( avalanche goldsource realvirtuality source spark unity3d unreal unreal2 )
  60. for allowed_engine in "${allowed_engines_array[@]}"
  61. do
  62. if [ "${allowed_engine}" == "${engine}" ]; then
  63. monitor_gsquery.sh
  64. fi
  65. done
  66. exit
  67. else
  68. fn_print_fail "Checking session: "
  69. fn_print_fail_eol_nl
  70. fn_script_log_error "Checking session: FAIL"
  71. alert="restart"
  72. alert.sh
  73. fn_script_log_info "Monitor is starting ${servername}"
  74. sleep 1
  75. command_start.sh
  76. fi
  77. }
  78. check.sh
  79. logs.sh
  80. info_config.sh
  81. fn_print_dots "${servername}"
  82. fn_script_log "${servername}"
  83. sleep 1
  84. fn_monitor_check_lockfile
  85. fn_monitor_check_update
  86. fn_monitor_msg_checking
  87. if [ "${gamename}" == "Teamspeak 3" ]; then
  88. fn_monitor_teamspeak3
  89. else
  90. fn_monitor_tmux
  91. fi