command_monitor.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. # LGSM command_monitor.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. lgsm_version="060516"
  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. 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_scriptlog "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_scriptlog "Checking session: CHECKING"
  32. sleep 1
  33. }
  34. fn_monitor_email_alert(){
  35. # Email will be sent if enabled
  36. if [ "${emailalert}" = "on" ]; then
  37. alertsubject="LGSM - Restarted - ${servername}"
  38. alertbody="${servicename} process not running"
  39. alert.sh
  40. fi
  41. }
  42. fn_monitor_teamspeak3(){
  43. if [ "${status}" != "0" ]; then
  44. fn_print_ok "Checking session: "
  45. fn_print_ok_eol_nl
  46. fn_scriptlog "Checking session: OK"
  47. exit
  48. else
  49. fn_print_fail "Checking session: ${ts3error}: "
  50. fn_print_fail_eol_nl
  51. fn_scriptlog "Checking session: ${ts3error}: FAIL"
  52. failurereason="${ts3error}"
  53. fn_monitor_email_alert
  54. fi
  55. fn_scriptlog "Monitor is starting ${servername}"
  56. sleep 1
  57. fn_restart
  58. }
  59. fn_monitor_tmux(){
  60. # checks that tmux session is running
  61. if [ "${status}" != "0" ]; then
  62. fn_print_ok "Checking session: "
  63. fn_print_ok_eol_nl
  64. fn_scriptlog "Checking session: OK"
  65. # runs gsquery check on game with specific engines.
  66. local allowed_engines_array=( avalanche goldsource realvirtuality source spark unity3d unreal unreal2 )
  67. for allowed_engine in "${allowed_engines_array[@]}"
  68. do
  69. if [ "${allowed_engine}" == "${function_selfname}" ]; then
  70. monitor_gsquery.sh
  71. fi
  72. done
  73. exit
  74. else
  75. fn_print_fail "Checking session: "
  76. fn_print_fail_eol_nl
  77. fn_scriptlog "Checking session: FAIL"
  78. fn_monitor_email_alert
  79. fn_scriptlog "Monitor is starting ${servername}"
  80. sleep 1
  81. command_start.sh
  82. fi
  83. }
  84. check.sh
  85. logs.sh
  86. info_config.sh
  87. fn_print_dots "${servername}"
  88. fn_scriptlog "${servername}"
  89. sleep 1
  90. fn_monitor_check_lockfile
  91. fn_monitor_check_update
  92. fn_monitor_msg_checking
  93. if [ "${gamename}" == "Teamspeak 3" ]; then
  94. fn_monitor_teamspeak3
  95. else
  96. fn_monitor_tmux
  97. fi