4
0

command_start.sh 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #!/bin/bash
  2. # LGSM command_start.sh function
  3. # Author: Daniel Gibbs
  4. # Website: http://gameservermanagers.com
  5. lgsm_version="070116"
  6. # Description: Starts the server.
  7. local modulename="Starting"
  8. function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  9. fn_start_teamspeak3(){
  10. check.sh
  11. info_ts3status.sh
  12. if [ "${ts3status}" != "Server is running" ]; then
  13. # Will check for updates is updateonstart is yes
  14. if [ "${updateonstart}" == "yes" ]||[ "${updateonstart}" == "1" ]||[ "${updateonstart}" == "on" ]; then
  15. update_check.sh
  16. fi
  17. fi
  18. if [ ! -e "${servercfgfullpath}" ]; then
  19. fn_print_warn "${servercfgfullpath} is missing"
  20. fn_scriptlog "${servercfgfullpath} is missing"
  21. sleep 2
  22. echo -en "\n"
  23. echo " * Creating blank ${servercfg}"
  24. fn_scriptlog "Creating blank ${servercfg}"
  25. sleep 2
  26. echo " * ${servercfg} can remain blank by default."
  27. fn_scriptlog "${servercfgfullpath} can remain blank by default."
  28. sleep 2
  29. echo " * ${servercfg} is located in ${servercfgfullpath}."
  30. fn_scriptlog "${servercfg} is located in ${servercfgfullpath}."
  31. sleep 5
  32. touch "${servercfgfullpath}"
  33. fi
  34. logs.sh
  35. fn_print_dots "${servername}"
  36. fn_scriptlog "${servername}"
  37. sleep 1
  38. if [ "${ts3status}" == "Server is running" ]; then
  39. fn_print_info "${servername} is already running"
  40. fn_scriptlog "${servername} is already running"
  41. sleep 1
  42. echo -en "\n"
  43. exit
  44. fi
  45. mv "${scriptlog}" "${scriptlogdate}"
  46. # Create lock file
  47. date > "${rootdir}/${lockselfname}"
  48. cd "${executabledir}"
  49. if [ "${ts3serverpass}" == "1" ];then
  50. ./ts3server_startscript.sh start serveradmin_password="${newpassword}"
  51. else
  52. ./ts3server_startscript.sh start inifile="${servercfgfullpath}" > /dev/null 2>&1
  53. fi
  54. sleep 1
  55. info_ts3status.sh
  56. if [ "${ts3status}" = "Server seems to have died" ]||[ "${ts3status}" = "No server running (ts3server.pid is missing)" ]; then
  57. fn_print_fail_nl "Unable to start ${servername}"
  58. fn_scriptlog "Unable to start ${servername}"
  59. echo -e " Check log files: ${rootdir}/log"
  60. exit 1
  61. else
  62. fn_print_ok "${servername}"
  63. fn_scriptlog "Started ${servername}"
  64. fi
  65. sleep 0.5
  66. echo -en "\n"
  67. }
  68. fn_start_tmux(){
  69. check.sh
  70. fix.sh
  71. info_config.sh
  72. fn_parms
  73. logs.sh
  74. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  75. # Will check for updates if updateonstart is yes
  76. if [ "${tmuxwc}" -eq 0 ]; then
  77. if [ "${updateonstart}" == "yes" ]||[ "${updateonstart}" == "1" ]||[ "${updateonstart}" == "on" ]; then
  78. update_check.sh
  79. fi
  80. fi
  81. fn_print_dots "${servername}"
  82. fn_scriptlog "${servername}"
  83. sleep 1
  84. if [ "${tmuxwc}" -eq 0 ]; then
  85. fn_scriptlog "Rotating log files"
  86. if [ "${engine}" == "unreal2" ]; then
  87. mv "${gamelog}" "${gamelogdate}"
  88. fi
  89. mv "${scriptlog}" "${scriptlogdate}"
  90. mv "${consolelog}" "${consolelogdate}"
  91. fi
  92. if [ "${tmuxwc}" -eq 1 ]; then
  93. fn_print_info_nl "${servername} is already running"
  94. fn_scriptlog "${servername} is already running"
  95. exit
  96. fi
  97. # Create lock file
  98. date > "${rootdir}/${lockselfname}"
  99. cd "${executabledir}"
  100. tmux new-session -d -s "${servicename}" "${executable} ${parms}" 2> "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  101. # tmux pipe-pane not supported in tmux versions < 1.6
  102. if [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd '[:digit:]')" -lt "16" ]; then
  103. echo "Console logging disabled: Tmux => 1.6 required" >> "${consolelog}"
  104. echo "http://gameservermanagers.com/tmux-upgrade" >> "${consolelog}"
  105. echo "Currently installed: $(tmux -V)" >> "${consolelog}"
  106. elif [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd '[:digit:]')" -eq "18" ]; then
  107. echo "Console logging disabled: Bug in tmux 1.8 breaks logging" >> "${consolelog}"
  108. echo "http://gameservermanagers.com/tmux-upgrade" >> "${consolelog}"
  109. echo "Currently installed: $(tmux -V)" >> "${consolelog}"
  110. else
  111. touch "${consolelog}"
  112. tmux pipe-pane -o -t "${servicename}" "exec cat >> '${consolelog}'"
  113. fi
  114. sleep 1
  115. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
  116. # If the server fails to start
  117. if [ "${tmuxwc}" -eq 0 ]; then
  118. fn_print_fail_nl "Unable to start ${servername}"
  119. fn_scriptlog "Unable to start ${servername}"
  120. sleep 1
  121. if [ -s "${scriptlogdir}/.${servicename}-tmux-error.tmp" ]; then
  122. fn_print_fail_nl "Unable to start ${servername}: Tmux error:"
  123. fn_scriptlog "Tmux error"
  124. echo ""
  125. echo "Command"
  126. echo "================================="
  127. echo "tmux new-session -d -s \"${servicename}\" \"${executable} ${parms}\""
  128. echo "tmux new-session -d -s \"${servicename}\" \"${executable} ${parms}\"" >> "${scriptlog}"
  129. echo ""
  130. echo "Error"
  131. echo "================================="
  132. cat "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  133. cat "${scriptlogdir}/.${servicename}-tmux-error.tmp" >> "${scriptlog}"
  134. # Detected error http://gameservermanagers.com/issues
  135. if [ $(grep -c "Operation not permitted" "${scriptlogdir}/.${servicename}-tmux-error.tmp") ]; then
  136. echo ""
  137. echo "Fix"
  138. echo "================================="
  139. if [ ! $(grep "tty:" /etc/group|grep "$(whoami)") ]; then
  140. echo "$(whoami) is not part of the tty group."
  141. fn_scriptlog "$(whoami) is not part of the tty group."
  142. group=$(grep tty /etc/group)
  143. echo ""
  144. echo " ${group}"
  145. fn_scriptlog "${group}"
  146. echo ""
  147. echo "Run the following command with root privileges."
  148. echo ""
  149. echo " usermod -G tty $(whoami)"
  150. echo ""
  151. echo "http://gameservermanagers.com/tmux-op-perm"
  152. fn_scriptlog "http://gameservermanagers.com/tmux-op-perm"
  153. else
  154. echo "No known fix currently. Please log an issue."
  155. fn_scriptlog "No known fix currently. Please log an issue."
  156. echo "http://gameservermanagers.com/issues"
  157. fn_scriptlog "http://gameservermanagers.com/issues"
  158. fi
  159. fi
  160. fi
  161. exit 1
  162. else
  163. fn_print_ok "${servername}"
  164. fn_scriptlog "Started ${servername}"
  165. fi
  166. rm "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  167. echo -en "\n"
  168. }
  169. if [ "${gamename}" == "Teamspeak 3" ]; then
  170. fn_start_teamspeak3
  171. else
  172. fn_start_tmux
  173. fi