command_start.sh 7.1 KB

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