command_monitor.sh 2.9 KB

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