fn_monitor 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/bash
  2. # LGSM fn_monitor function
  3. # Author: Daniel Gibbs
  4. # Website: http://gameservermanagers.com
  5. # Version: 310515
  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 "${rootdir}/${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 "${rootdir}/${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. if [ "${gamename}" != "Mumble" ]; then
  80. fn_monitor_query
  81. fi
  82. exit
  83. else
  84. fn_printfail "Checking session: FAIL"
  85. fn_scriptlog "Checking session: FAIL"
  86. sleep 1
  87. echo -en "\n"
  88. if [ "${emailnotification}" = "on" ]; then
  89. subject="${servicename} Monitor - Starting ${servername}"
  90. failurereason="${servicename} process not running"
  91. actiontaken="${servicename} has been restarted"
  92. fn_email
  93. fi
  94. fn_scriptlog "Monitor is starting ${servername}"
  95. fn_start
  96. fi
  97. else
  98. fn_printinfonl "SteamCMD is currently checking for updates"
  99. fn_scriptlog "SteamCMD is currently checking for updates"
  100. sleep 1
  101. fn_printinfonl "When update is complete ${servicename} will start"
  102. fn_scriptlog "When update is complete ${servicename} will start"
  103. sleep 1
  104. fi
  105. }
  106. if [ "${gamename}" == "Teamspeak 3" ]; then
  107. fn_monitor_teamspeak3
  108. else
  109. fn_monitor_tmux
  110. fi