command_monitor.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/bash
  2. # LGSM command_monitor.sh function
  3. # Author: Daniel Gibbs
  4. # Website: http://gameservermanagers.com
  5. lgsm_version="271215"
  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_scriptlog "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. updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
  22. if [ "${updatecheck}" >= "0" ]; then
  23. fn_print_info_nl "SteamCMD is currently checking for updates"
  24. fn_scriptlog "SteamCMD is currently checking for updates"
  25. sleep 1
  26. exit
  27. fi
  28. }
  29. fn_monitor_msg_checking(){
  30. fn_print_dots "Checking session: CHECKING"
  31. fn_scriptlog "Checking session: CHECKING"
  32. sleep 1
  33. }
  34. fn_monitor_email_notification(){
  35. # Email will be sent if enabled
  36. if [ "${emailnotification}" = "on" ]; then
  37. subject="${servicename} Monitor - Starting ${servername}"
  38. failurereason="${servicename} process not running"
  39. actiontaken="${servicename} has been restarted"
  40. email.sh
  41. fi
  42. }
  43. fn_monitor_teamspeak3(){
  44. info_ts3status.sh
  45. if [ "${ts3status}" = "Server is running" ]; then
  46. fn_print_ok "Checking session: "
  47. fn_print_ok_eol_nl
  48. fn_scriptlog "Checking session: OK"
  49. exit
  50. else
  51. fn_print_fail "Checking session: ${ts3status}: "
  52. fn_print_fail_eol_nl
  53. fn_scriptlog "Checking session: ${ts3status}: FAIL"
  54. failurereason="${ts3status}"
  55. fn_monitor_email_notification
  56. fi
  57. fn_scriptlog "Monitor is starting ${servername}"
  58. sleep 1
  59. fn_restart
  60. }
  61. fn_monitor_tmux(){
  62. # checks that tmux session is running
  63. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
  64. if [ "${tmuxwc}" == "1" ]; then
  65. fn_print_ok "Checking session: OK"
  66. fn_print_ok_eol_nl
  67. fn_scriptlog "Checking session: OK"
  68. # runs gsquery check on game with specific engines.
  69. local allowed_engines_array=( avalanche goldsource realvirtuality source spark unity3d unreal unreal2 )
  70. for allowed_engine in "${allowed_engines_array[@]}"
  71. do
  72. if [ "${allowed_engine}" == "${function_selfname}" ]; then
  73. monitor_gsquery.sh
  74. fi
  75. done
  76. exit
  77. else
  78. fn_print_fail "Checking session: FAIL"
  79. fn_print_fail_eol_nl
  80. fn_scriptlog "Checking session: FAIL"
  81. fn_monitor_email_notification
  82. fn_scriptlog "Monitor is starting ${servername}"
  83. sleep 1
  84. command_start.sh
  85. fi
  86. }
  87. check.sh
  88. logs.sh
  89. info_config.sh
  90. fn_print_dots "${servername}"
  91. fn_scriptlog "${servername}"
  92. sleep 1
  93. fn_monitor_check_lockfile
  94. fn_monitor_check_update
  95. fn_monitor_msg_checking
  96. if [ "${gamename}" == "Teamspeak 3" ]; then
  97. fn_monitor_teamspeak3
  98. else
  99. fn_monitor_tmux
  100. fi