command_start.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #!/bin/bash
  2. # LinuxGSM command_start.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://linuxgsm.com
  6. # Description: Starts the server.
  7. local commandname="START"
  8. local commandaction="Starting"
  9. local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. fn_start_teamspeak3(){
  11. if [ ! -e "${servercfgfullpath}" ]; then
  12. fn_print_warn_nl "${servercfgfullpath} is missing"
  13. fn_script_log_warn "${servercfgfullpath} is missing"
  14. echo " * Creating blank ${servercfg}"
  15. fn_script_log_info "Creating blank ${servercfg}"
  16. sleep 1
  17. echo " * ${servercfg} can remain blank by default."
  18. fn_script_log_info "${servercfgfullpath} can remain blank by default."
  19. sleep 1
  20. echo " * ${servercfg} is located in ${servercfgfullpath}."
  21. fn_script_log_info "${servercfg} is located in ${servercfgfullpath}."
  22. sleep 5
  23. touch "${servercfgfullpath}"
  24. fi
  25. sleep 0.5
  26. if [ -f "${lgsmlog}" ]; then
  27. mv "${lgsmlog}" "${lgsmlogdate}"
  28. fi
  29. # Create lockfile
  30. date > "${rootdir}/${lockselfname}"
  31. # Accept license
  32. if [ ! -f "${executabledir}/.ts3server_license_accepted" ]; then
  33. install_eula.sh
  34. fi
  35. cd "${executabledir}"
  36. if [ "${ts3serverpass}" == "1" ]; then
  37. ./ts3server_startscript.sh start serveradmin_password="${newpassword}" inifile="${servercfgfullpath}" > /dev/null 2>&1
  38. else
  39. ./ts3server_startscript.sh start inifile="${servercfgfullpath}" > /dev/null 2>&1
  40. fi
  41. sleep 0.5
  42. check_status.sh
  43. if [ "${status}" == "0" ]; then
  44. fn_print_fail_nl "Unable to start ${servername}"
  45. fn_script_log_fatal "Unable to start ${servername}"
  46. echo -e " Check log files: ${logdir}"
  47. core_exit.sh
  48. else
  49. fn_print_ok_nl "${servername}"
  50. fn_script_log_pass "Started ${servername}"
  51. fi
  52. }
  53. fn_start_tmux(){
  54. if [ "${parmsbypass}" ]; then
  55. parms=""
  56. else
  57. fn_parms
  58. fi
  59. # check for tmux size variables
  60. if [[ "${servercfgtmuxwidth}" =~ ^[0-9]+$ ]]; then
  61. sessionwidth="${servercfgtmuxwidth}"
  62. else
  63. sessionwidth="80"
  64. fi
  65. if [[ "${servercfgtmuxheight}" =~ ^[0-9]+$ ]]; then
  66. sessionheight="${servercfgtmuxheight}"
  67. else
  68. sessionheight="23"
  69. fi
  70. # Log rotation
  71. fn_script_log_info "Rotating log files"
  72. if [ "${engine}" == "unreal2" ]&&[ -f "${gamelog}" ]; then
  73. mv "${gamelog}" "${gamelogdate}"
  74. fi
  75. if [ -f "${lgsmlog}" ]; then
  76. mv "${lgsmlog}" "${lgsmlogdate}"
  77. fi
  78. if [ -f "${consolelog}" ]; then
  79. mv "${consolelog}" "${consolelogdate}"
  80. fi
  81. # Create lockfile
  82. date > "${rootdir}/${lockselfname}"
  83. cd "${executabledir}"
  84. tmux new-session -d -x "${sessionwidth}" -y "${sessionheight}" -s "${servicename}" "${executable} ${parms}" 2> "${lgsmlogdir}/.${servicename}-tmux-error.tmp"
  85. # Create logfile
  86. touch "${consolelog}"
  87. # Get tmux version
  88. tmuxversion="$(tmux -V | sed "s/tmux //" | sed -n '1 p')"
  89. # Tmux compiled from source will return "master", therefore ignore it
  90. if [ "$(tmux -V | sed "s/tmux //" | sed -n '1 p')" == "master" ]; then
  91. fn_script_log "Tmux version: master (user compiled)"
  92. echo "Tmux version: master (user compiled)" >> "${consolelog}"
  93. if [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then
  94. tmux pipe-pane -o -t "${servicename}" "exec cat >> '${consolelog}'"
  95. fi
  96. elif [ -n "${tmuxversion}" ]; then
  97. # Get the digit version of tmux
  98. tmuxversion="$(tmux -V | sed "s/tmux //" | sed -n '1 p' | tr -cd '[:digit:]')"
  99. # tmux pipe-pane not supported in tmux versions < 1.6
  100. if [ "${tmuxversion}" -lt "16" ]; then
  101. echo "Console logging disabled: Tmux => 1.6 required
  102. https://linuxgsm.com/tmux-upgrade
  103. Currently installed: $(tmux -V)" > "${consolelog}"
  104. # Console logging disabled: Bug in tmux 1.8 breaks logging
  105. elif [ "${tmuxversion}" -eq "18" ]; then
  106. echo "Console logging disabled: Bug in tmux 1.8 breaks logging
  107. https://linuxgsm.com/tmux-upgrade
  108. Currently installed: $(tmux -V)" > "${consolelog}"
  109. # Console logging enable or not set
  110. elif [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then
  111. tmux pipe-pane -o -t "${servicename}" "exec cat >> '${consolelog}'"
  112. fi
  113. else
  114. echo "Unable to detect tmux version" >> "${consolelog}"
  115. fn_script_log_warn "Unable to detect tmux version"
  116. fi
  117. # Console logging disabled
  118. if [ "${consolelogging}" == "off" ]; then
  119. echo "Console logging disabled by user" >> "${consolelog}"
  120. fn_script_log_info "Console logging disabled by user"
  121. fi
  122. sleep 0.5
  123. # If the server fails to start
  124. check_status.sh
  125. if [ "${status}" == "0" ]; then
  126. fn_print_fail_nl "Unable to start ${servername}"
  127. fn_script_log_fatal "Unable to start ${servername}"
  128. sleep 0.5
  129. if [ -s "${lgsmlogdir}/.${servicename}-tmux-error.tmp" ]; then
  130. fn_print_fail_nl "Unable to start ${servername}: Tmux error:"
  131. fn_script_log_fatal "Unable to start ${servername}: Tmux error:"
  132. echo ""
  133. echo "Command"
  134. echo "================================="
  135. echo "tmux new-session -d -s \"${servicename}\" \"${executable} ${parms}\"" | tee -a "${lgsmlog}"
  136. echo ""
  137. echo "Error"
  138. echo "================================="
  139. cat "${lgsmlogdir}/.${servicename}-tmux-error.tmp" | tee -a "${lgsmlog}"
  140. # Detected error https://linuxgsm.com/support
  141. if grep -c "Operation not permitted" "${lgsmlogdir}/.${servicename}-tmux-error.tmp"
  142. 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_script_log_info "$(whoami) is not part of the tty group."
  149. group=$(grep tty /etc/group)
  150. echo ""
  151. echo " ${group}"
  152. fn_script_log_info "${group}"
  153. echo ""
  154. echo "Run the following command with root privileges."
  155. echo ""
  156. echo " usermod -G tty $(whoami)"
  157. echo ""
  158. echo "https://linuxgsm.com/tmux-op-perm"
  159. fn_script_log_info "https://linuxgsm.com/tmux-op-perm"
  160. else
  161. echo "No known fix currently. Please log an issue."
  162. fn_script_log_info "No known fix currently. Please log an issue."
  163. echo "https://linuxgsm.com/support"
  164. fn_script_log_info "https://linuxgsm.com/support"
  165. fi
  166. fi
  167. fi
  168. core_exit.sh
  169. else
  170. fn_print_ok "${servername}"
  171. fn_script_log_pass "Started ${servername}"
  172. fi
  173. rm "${lgsmlogdir}/.${servicename}-tmux-error.tmp"
  174. echo -en "\n"
  175. }
  176. fn_print_dots "${servername}"
  177. sleep 0.5
  178. check.sh
  179. # Is the server already started
  180. if [ "${status}" != "0" ]; then # $status comes from check_status.sh, which is run by check.sh for this command
  181. fn_print_info_nl "${servername} is already running"
  182. fn_script_log_error "${servername} is already running"
  183. if [ -z "${exitbypass}" ]; then
  184. core_exit.sh
  185. fi
  186. fi
  187. if [ -z "${fixbypass}" ];then
  188. fix.sh
  189. fi
  190. info_config.sh
  191. logs.sh
  192. # Will check for updates is updateonstart is yes
  193. if [ "${updateonstart}" == "yes" ]||[ "${updateonstart}" == "1" ]||[ "${updateonstart}" == "on" ]; then
  194. exitbypass=1
  195. unset updateonstart
  196. command_update.sh
  197. fi
  198. if [ "${shortname}" == "ts3" ]; then
  199. fn_start_teamspeak3
  200. else
  201. fn_start_tmux
  202. fi
  203. core_exit.sh