command_start.sh 5.8 KB

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