command_monitor.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. fn_monitor_teamspeak3(){
  10. check.sh
  11. logs.sh
  12. fn_printdots "${servername}"
  13. fn_scriptlog "${servername}"
  14. sleep 1
  15. if [ ! -f "${rootdir}/${lockselfname}" ]; then
  16. fn_printinfo "Disabled: No lock file found"
  17. fn_scriptlog "Disabled: No lock file found"
  18. sleep 1
  19. echo -en "\n"
  20. echo "To enable monitor run ./${selfname} start"
  21. exit 1
  22. fi
  23. fn_printdots "Checking session: CHECKING"
  24. fn_scriptlog "Checking session: CHECKING"
  25. sleep 1
  26. info_ts3status.sh
  27. if [ "${ts3status}" = "Server is running" ]; then
  28. fn_printok "Checking session: OK"
  29. fn_scriptlog "Checking session: OK"
  30. sleep 1
  31. sleep 0.5
  32. echo -en "\n"
  33. exit
  34. else
  35. fn_printfail "Checking session: FAIL"
  36. fn_scriptlog "Checking session: FAIL"
  37. sleep 1
  38. fn_printfail "Checking session: FAIL: ${ts3status}"
  39. fn_scriptlog "Checking session: FAIL: ${ts3status}"
  40. failurereason="${ts3status}"
  41. if [ "${emailnotification}" = "on" ]; then
  42. subject="${servicename} Monitor - Restarting ${servername}"
  43. actiontaken="restarted ${servername}"
  44. email.sh
  45. fi
  46. fi
  47. sleep 0.5
  48. echo -en "\n"
  49. fn_restart
  50. }
  51. fn_monitor_tmux(){
  52. check.sh
  53. info_config.sh
  54. fn_printdots "${servername}"
  55. fn_scriptlog "${servername}"
  56. sleep 1
  57. if [ ! -f "${rootdir}/${lockselfname}" ]; then
  58. fn_printinfo "Disabled: No lock file found"
  59. fn_scriptlog "Disabled: No lock file found"
  60. sleep 1
  61. echo -en "\n"
  62. echo "To enable monitor run ./${selfname} start"
  63. exit 1
  64. fi
  65. updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
  66. if [ "${updatecheck}" = "0" ]||[ "${gamename}" == "Unreal Tournament 99" ]||[ "${gamename}" == "Unreal Tournament 2004" ]; then
  67. fn_printdots "Checking session: CHECKING"
  68. fn_scriptlog "Checking session: CHECKING"
  69. sleep 1
  70. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  71. if [ "${tmuxwc}" -eq 1 ]; then
  72. fn_printok "Checking session: OK"
  73. fn_scriptlog "Checking session: OK"
  74. sleep 1
  75. echo -en "\n"
  76. if [ "${engine}" == "avalanche" ]||[ "${engine}" == "goldsource" ]||[ "${engine}" == "realvirtuality" ]||[ "${engine}" == "source" ]||[ "${engine}" == "spark" ]||[ "${engine}" == "unity3d" ]||[ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
  77. monitor_gsquery.sh
  78. fi
  79. exit $?
  80. else
  81. fn_printfail "Checking session: FAIL"
  82. fn_scriptlog "Checking session: FAIL"
  83. sleep 1
  84. echo -en "\n"
  85. if [ "${emailnotification}" = "on" ]; then
  86. subject="${servicename} Monitor - Starting ${servername}"
  87. failurereason="${servicename} process not running"
  88. actiontaken="${servicename} has been restarted"
  89. email.sh
  90. fi
  91. fn_scriptlog "Monitor is starting ${servername}"
  92. command_start.sh
  93. fi
  94. else
  95. fn_printinfonl "SteamCMD is currently checking for updates"
  96. fn_scriptlog "SteamCMD is currently checking for updates"
  97. sleep 1
  98. fn_printinfonl "When update is complete ${servicename} will start"
  99. fn_scriptlog "When update is complete ${servicename} will start"
  100. sleep 1
  101. fi
  102. }
  103. if [ "${gamename}" == "Teamspeak 3" ]; then
  104. fn_monitor_teamspeak3
  105. else
  106. fn_monitor_tmux
  107. fi