fn_monitor 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/bash
  2. # LGSM fn_monitor function
  3. # Author: Daniel Gibbs
  4. # Website: http://gameservermanagers.com
  5. # Version: 230315
  6. # Description: Monitors server by checking for running proccesses
  7. # then passes to fn_monitor_query.
  8. local modulename="Monitor"
  9. fn_monitor_teamspeak3(){
  10. fn_check_root
  11. fn_check_systemdir
  12. fn_logs
  13. fn_printdots "${servername}"
  14. fn_scriptlog "${servername}"
  15. sleep 1
  16. if [ ! -f "${lockselfname}" ]; then
  17. fn_printinfo "Disabled: No lock file found"
  18. fn_scriptlog "Disabled: No lock file found"
  19. sleep 1
  20. echo -en "\n"
  21. echo "To enable monitor run ./${selfname} start"
  22. exit
  23. fi
  24. fn_printdots "Checking session: CHECKING"
  25. fn_scriptlog "Checking session: CHECKING"
  26. sleep 1
  27. fn_check_ts3status
  28. if [ "${ts3status}" = "Server is running" ]; then
  29. fn_printok "Checking session: OK"
  30. fn_scriptlog "Checking session: OK"
  31. sleep 1
  32. sleep 0.5
  33. echo -en "\n"
  34. exit
  35. else
  36. fn_printfail "Checking session: FAIL"
  37. fn_scriptlog "Checking session: FAIL"
  38. sleep 1
  39. fn_printfail "Checking session: FAIL: ${ts3status}"
  40. fn_scriptlog "Checking session: FAIL: ${ts3status}"
  41. failurereason="${ts3status}"
  42. if [ "${emailnotification}" = "on" ]; then
  43. subject="${servicename} Monitor - Restarting ${servername}"
  44. actiontaken="restarted ${servername}"
  45. fn_emailnotification
  46. fi
  47. fi
  48. sleep 0.5
  49. echo -en "\n"
  50. fn_restart
  51. }
  52. fn_monitor_tmux(){
  53. fn_check_root
  54. fn_check_systemdir
  55. fn_check_ip
  56. fn_details_config
  57. fn_printdots "${servername}"
  58. fn_scriptlog "${servername}"
  59. sleep 1
  60. if [ ! -f "${lockselfname}" ]; then
  61. fn_printinfo "Disabled: No lock file found"
  62. fn_scriptlog "Disabled: No lock file found"
  63. sleep 1
  64. echo -en "\n"
  65. echo "To enable monitor run ./${selfname} start"
  66. exit
  67. fi
  68. updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
  69. if [ "${updatecheck}" = "0" ]||[ "${gamename}" == "Unreal Tournament 99" ]||[ "${gamename}" == "Unreal Tournament 2004" ]; then
  70. fn_printdots "Checking session: CHECKING"
  71. fn_scriptlog "Checking session: CHECKING"
  72. sleep 1
  73. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  74. if [ "${tmuxwc}" -eq 1 ]; then
  75. fn_printok "Checking session: OK"
  76. fn_scriptlog "Checking session: OK"
  77. sleep 1
  78. echo -en "\n"
  79. fn_monitor_query
  80. exit
  81. else
  82. fn_printfail "Checking session: FAIL"
  83. fn_scriptlog "Checking session: FAIL"
  84. sleep 1
  85. echo -en "\n"
  86. if [ "${emailnotification}" = "on" ]; then
  87. subject="${servicename} Monitor - Starting ${servername}"
  88. failurereason="${servicename} process not running"
  89. actiontaken="${servicename} has been restarted"
  90. fn_email
  91. fi
  92. fn_scriptlog "Monitor is starting ${servername}"
  93. fn_start
  94. fi
  95. else
  96. fn_printinfonl "SteamCMD is currently checking for updates"
  97. fn_scriptlog "SteamCMD is currently checking for updates"
  98. sleep 1
  99. fn_printinfonl "When update is complete ${servicename} will start"
  100. fn_scriptlog "When update is complete ${servicename} will start"
  101. sleep 1
  102. fi
  103. }
  104. if [ "${gamename}" == "Teamspeak 3" ]; then
  105. fn_monitor_teamspeak3
  106. else
  107. fn_monitor_tmux
  108. fi