command_start.sh 6.0 KB

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