4
0

command_monitor.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. fn_monitor_teamspeak3(){
  11. check.sh
  12. logs.sh
  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 1
  23. fi
  24. fn_printdots "Checking session: CHECKING"
  25. fn_scriptlog "Checking session: CHECKING"
  26. sleep 1
  27. info_ts3status.sh
  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. email.sh
  46. fi
  47. fi
  48. sleep 0.5
  49. echo -en "\n"
  50. fn_restart
  51. }
  52. fn_monitor_tmux(){
  53. check.sh
  54. info_config.sh
  55. fn_printdots "${servername}"
  56. fn_scriptlog "${servername}"
  57. sleep 1
  58. if [ ! -f "${rootdir}/${lockselfname}" ]; then
  59. fn_printinfo "Disabled: No lock file found"
  60. fn_scriptlog "Disabled: No lock file found"
  61. sleep 1
  62. echo -en "\n"
  63. echo "To enable monitor run ./${selfname} start"
  64. exit 1
  65. fi
  66. updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
  67. if [ "${updatecheck}" = "0" ]||[ "${gamename}" == "Unreal Tournament 99" ]||[ "${gamename}" == "Unreal Tournament 2004" ]; then
  68. fn_printdots "Checking session: CHECKING"
  69. fn_scriptlog "Checking session: CHECKING"
  70. sleep 1
  71. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  72. if [ "${tmuxwc}" -eq 1 ]; then
  73. fn_printok "Checking session: OK"
  74. fn_scriptlog "Checking session: OK"
  75. sleep 1
  76. echo -en "\n"
  77. if [ "${engine}" == "avalanche" ]||[ "${engine}" == "goldsource" ]||[ "${engine}" == "idtech3" ]||[ "${engine}" == "realvirtuality" ]||[ "${engine}" == "source" ]||[ "${engine}" == "spark" ]||[ "${engine}" == "unity3d" ]||[ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
  78. monitor_gsquery.sh
  79. fi
  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. email.sh
  91. fi
  92. fn_scriptlog "Monitor is starting ${servername}"
  93. command_start.sh
  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