command_monitor.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. alert="restart"
  54. alert.sh
  55. fi
  56. fn_scriptlog "Monitor is starting ${servername}"
  57. sleep 1
  58. fn_restart
  59. }
  60. fn_monitor_tmux(){
  61. # checks that tmux session is running
  62. if [ "${status}" != "0" ]; then
  63. fn_print_ok "Checking session: "
  64. fn_print_ok_eol_nl
  65. fn_scriptlog "Checking session: OK"
  66. # runs gsquery check on game with specific engines.
  67. local allowed_engines_array=( avalanche goldsource realvirtuality source spark unity3d unreal unreal2 )
  68. for allowed_engine in "${allowed_engines_array[@]}"
  69. do
  70. if [ "${allowed_engine}" == "${function_selfname}" ]; then
  71. monitor_gsquery.sh
  72. fi
  73. done
  74. exit
  75. else
  76. fn_print_fail "Checking session: "
  77. fn_print_fail_eol_nl
  78. fn_scriptlog "Checking session: FAIL"
  79. fn_monitor_email_alert
  80. fn_scriptlog "Monitor is starting ${servername}"
  81. sleep 1
  82. command_start.sh
  83. fi
  84. }
  85. check.sh
  86. logs.sh
  87. info_config.sh
  88. fn_print_dots "${servername}"
  89. fn_scriptlog "${servername}"
  90. sleep 1
  91. fn_monitor_check_lockfile
  92. fn_monitor_check_update
  93. fn_monitor_msg_checking
  94. if [ "${gamename}" == "Teamspeak 3" ]; then
  95. fn_monitor_teamspeak3
  96. else
  97. fn_monitor_tmux
  98. fi