command_start.sh 5.9 KB

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