command_start.sh 6.1 KB

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