command_start.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. fn_script_log "Accepting ts3server license: ${executabledir}/LICENSE"
  34. fn_print_info_nl "Accepting TeamSpeak license:"
  35. echo " * ${executabledir}/LICENSE"
  36. sleep 3
  37. touch "${executabledir}/.ts3server_license_accepted"
  38. fi
  39. cd "${executabledir}"
  40. if [ "${ts3serverpass}" == "1" ]; then
  41. ./ts3server_startscript.sh start serveradmin_password="${newpassword}" inifile="${servercfgfullpath}" > /dev/null 2>&1
  42. else
  43. ./ts3server_startscript.sh start inifile="${servercfgfullpath}" > /dev/null 2>&1
  44. fi
  45. sleep 0.5
  46. check_status.sh
  47. if [ "${status}" == "0" ]; then
  48. fn_print_fail_nl "Unable to start ${servername}"
  49. fn_script_log_fatal "Unable to start ${servername}"
  50. echo -e " Check log files: ${logdir}"
  51. core_exit.sh
  52. else
  53. fn_print_ok_nl "${servername}"
  54. fn_script_log_pass "Started ${servername}"
  55. fi
  56. }
  57. fn_start_tmux(){
  58. fn_parms
  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" ]; then
  73. if [ -f "${gamelog}" ]; then
  74. mv "${gamelog}" "${gamelogdate}"
  75. fi
  76. mv "${lgsmlog}" "${lgsmlogdate}"
  77. mv "${consolelog}" "${consolelogdate}"
  78. fi
  79. # Create lockfile
  80. date > "${rootdir}/${lockselfname}"
  81. cd "${executabledir}"
  82. tmux new-session -d -x "${sessionheight}" -y "${sessionwidth}" -s "${servicename}" "${executable} ${parms}" 2> "${lgsmlogdir}/.${servicename}-tmux-error.tmp"
  83. # Create logfile
  84. touch "${consolelog}"
  85. # Get tmux version
  86. tmuxversion="$(tmux -V | sed "s/tmux //" | sed -n '1 p')"
  87. # Tmux compiled from source will return "master", therefore ignore it
  88. if [ "$(tmux -V | sed "s/tmux //" | sed -n '1 p')" == "master" ]; then
  89. fn_script_log "Tmux version: master (user compiled)"
  90. echo "Tmux version: master (user compiled)" >> "${consolelog}"
  91. if [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then
  92. tmux pipe-pane -o -t "${servicename}" "exec cat >> '${consolelog}'"
  93. fi
  94. elif [ -n "${tmuxversion}" ]; then
  95. # Get the digit version of tmux
  96. tmuxversion="$(tmux -V | sed "s/tmux //" | sed -n '1 p' | tr -cd '[:digit:]')"
  97. # tmux pipe-pane not supported in tmux versions < 1.6
  98. if [ "${tmuxversion}" -lt "16" ]; then
  99. echo "Console logging disabled: Tmux => 1.6 required
  100. https://linuxgsm.com/tmux-upgrade
  101. Currently installed: $(tmux -V)" > "${consolelog}"
  102. # Console logging disabled: Bug in tmux 1.8 breaks logging
  103. elif [ "${tmuxversion}" -eq "18" ]; then
  104. echo "Console logging disabled: Bug in tmux 1.8 breaks logging
  105. https://linuxgsm.com/tmux-upgrade
  106. Currently installed: $(tmux -V)" > "${consolelog}"
  107. # Console logging enable or not set
  108. elif [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then
  109. tmux pipe-pane -o -t "${servicename}" "exec cat >> '${consolelog}'"
  110. fi
  111. else
  112. echo "Unable to detect tmux version" >> "${consolelog}"
  113. fn_script_log_warn "Unable to detect tmux version"
  114. fi
  115. # Console logging disabled
  116. if [ "${consolelogging}" == "off" ]; then
  117. echo "Console logging disabled by user" >> "${consolelog}"
  118. fn_script_log_info "Console logging disabled by user"
  119. fi
  120. sleep 0.5
  121. # If the server fails to start
  122. check_status.sh
  123. if [ "${status}" == "0" ]; then
  124. fn_print_fail_nl "Unable to start ${servername}"
  125. fn_script_log_fatal "Unable to start ${servername}"
  126. sleep 0.5
  127. if [ -s "${lgsmlogdir}/.${servicename}-tmux-error.tmp" ]; then
  128. fn_print_fail_nl "Unable to start ${servername}: Tmux error:"
  129. fn_script_log_fatal "Unable to start ${servername}: Tmux error:"
  130. echo ""
  131. echo "Command"
  132. echo "================================="
  133. echo "tmux new-session -d -s \"${servicename}\" \"${executable} ${parms}\"" | tee -a "${lgsmlog}"
  134. echo ""
  135. echo "Error"
  136. echo "================================="
  137. cat "${lgsmlogdir}/.${servicename}-tmux-error.tmp" | tee -a "${lgsmlog}"
  138. # Detected error https://linuxgsm.com/support
  139. if grep -c "Operation not permitted" "${lgsmlogdir}/.${servicename}-tmux-error.tmp"
  140. then
  141. echo ""
  142. echo "Fix"
  143. echo "================================="
  144. if [ ! $(grep "tty:" /etc/group|grep "$(whoami)") ]; then
  145. echo "$(whoami) is not part of the tty group."
  146. fn_script_log_info "$(whoami) is not part of the tty group."
  147. group=$(grep tty /etc/group)
  148. echo ""
  149. echo " ${group}"
  150. fn_script_log_info "${group}"
  151. echo ""
  152. echo "Run the following command with root privileges."
  153. echo ""
  154. echo " usermod -G tty $(whoami)"
  155. echo ""
  156. echo "https://linuxgsm.com/tmux-op-perm"
  157. fn_script_log_info "https://linuxgsm.com/tmux-op-perm"
  158. else
  159. echo "No known fix currently. Please log an issue."
  160. fn_script_log_info "No known fix currently. Please log an issue."
  161. echo "https://linuxgsm.com/support"
  162. fn_script_log_info "https://linuxgsm.com/support"
  163. fi
  164. fi
  165. fi
  166. core_exit.sh
  167. else
  168. fn_print_ok "${servername}"
  169. fn_script_log_pass "Started ${servername}"
  170. fi
  171. rm "${lgsmlogdir}/.${servicename}-tmux-error.tmp"
  172. echo -en "\n"
  173. }
  174. fn_print_dots "${servername}"
  175. sleep 0.5
  176. check.sh
  177. # Is the server already started
  178. if [ "${status}" != "0" ]; then # $status comes from check_status.sh, which is run by check.sh for this command
  179. fn_print_info_nl "${servername} is already running"
  180. fn_script_log_error "${servername} is already running"
  181. if [ -z "${exitbypass}" ]; then
  182. core_exit.sh
  183. fi
  184. fi
  185. fix.sh
  186. info_config.sh
  187. logs.sh
  188. # Will check for updates is updateonstart is yes
  189. if [ "${updateonstart}" == "yes" ]||[ "${updateonstart}" == "1" ]||[ "${updateonstart}" == "on" ]; then
  190. exitbypass=1
  191. unset updateonstart
  192. command_update.sh
  193. fi
  194. if [ "${gamename}" == "TeamSpeak 3" ]; then
  195. fn_start_teamspeak3
  196. else
  197. fn_start_tmux
  198. fi
  199. core_exit.sh