command_start.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #!/bin/bash
  2. # LinuxGSM command_start.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://gameservermanagers.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 2
  17. echo " * ${servercfg} can remain blank by default."
  18. fn_script_log_info "${servercfgfullpath} can remain blank by default."
  19. sleep 2
  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 1
  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. 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 1
  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. check_status.sh
  72. if [ "${status}" == "0" ]; then
  73. fn_script_log_info "Rotating log files"
  74. if [ "${engine}" == "unreal2" ]; then
  75. if [ -f "${gamelog}" ]; then
  76. mv "${gamelog}" "${gamelogdate}"
  77. fi
  78. fi
  79. mv "${lgsmlog}" "${lgsmlogdate}"
  80. mv "${consolelog}" "${consolelogdate}"
  81. fi
  82. # If server is already running exit
  83. check_status.sh
  84. if [ "${status}" != "0" ]; then
  85. fn_print_info_nl "${servername} is already running"
  86. fn_script_log_error "${servername} is already running"
  87. if [ -z "${exitbypass}" ]; then
  88. core_exit.sh
  89. fi
  90. fi
  91. # Create lockfile
  92. date > "${rootdir}/${lockselfname}"
  93. cd "${executabledir}"
  94. tmux new-session -d -x "${sessionheight}" -y "${sessionwidth}" -s "${servicename}" "${executable} ${parms}" 2> "${lgsmlogdir}/.${servicename}-tmux-error.tmp"
  95. # Create logfile
  96. touch "${consolelog}"
  97. # Get tmux version
  98. tmuxversion="$(tmux -V|sed "s/tmux //"|sed -n '1 p')"
  99. # Tmux compiled from source will return "master", therefore ignore it
  100. if [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p')" == "master" ]; then
  101. fn_script_log "Tmux version: master (user compiled)"
  102. echo "Tmux version: master (user compiled)" >> "${consolelog}"
  103. if [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then
  104. tmux pipe-pane -o -t "=${servicename}" "exec cat >> '${consolelog}'"
  105. fi
  106. elif [ -n "${tmuxversion}" ]; then
  107. # Get the digit version of tmux
  108. tmuxversion="$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd '[:digit:]')"
  109. # tmux pipe-pane not supported in tmux versions < 1.6
  110. if [ "${tmuxversion}" -lt "16" ]; then
  111. echo "Console logging disabled: Tmux => 1.6 required
  112. https://gameservermanagers.com/tmux-upgrade
  113. Currently installed: $(tmux -V)" > "${consolelog}"
  114. # Console logging disabled: Bug in tmux 1.8 breaks logging
  115. elif [ "${tmuxversion}" -eq "18" ]; then
  116. echo "Console logging disabled: Bug in tmux 1.8 breaks logging
  117. https://gameservermanagers.com/tmux-upgrade
  118. Currently installed: $(tmux -V)" > "${consolelog}"
  119. # Console logging enable or not set
  120. elif [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then
  121. tmux pipe-pane -o -t "=${servicename}" "exec cat >> '${consolelog}'"
  122. fi
  123. else
  124. echo "Unable to detect tmux version" >> "${consolelog}"
  125. fn_script_log_warn "Unable to detect tmux version"
  126. fi
  127. # Console logging disabled
  128. if [ "${consolelogging}" == "off" ]; then
  129. echo "Console logging disabled by user" >> "${consolelog}"
  130. fn_script_log_info "Console logging disabled by user"
  131. fi
  132. sleep 1
  133. # If the server fails to start
  134. check_status.sh
  135. if [ "${status}" == "0" ]; then
  136. fn_print_fail_nl "Unable to start ${servername}"
  137. fn_script_log_fatal "Unable to start ${servername}"
  138. sleep 1
  139. if [ -s "${lgsmlogdir}/.${servicename}-tmux-error.tmp" ]; then
  140. fn_print_fail_nl "Unable to start ${servername}: Tmux error:"
  141. fn_script_log_fatal "Unable to start ${servername}: Tmux error:"
  142. echo ""
  143. echo "Command"
  144. echo "================================="
  145. echo "tmux new-session -d -s \"${servicename}\" \"${executable} ${parms}\"" | tee -a "${lgsmlog}"
  146. echo ""
  147. echo "Error"
  148. echo "================================="
  149. cat "${lgsmlogdir}/.${servicename}-tmux-error.tmp" | tee -a "${lgsmlog}"
  150. # Detected error https://gameservermanagers.com/support
  151. if [ $(grep -c "Operation not permitted" "${lgsmlogdir}/.${servicename}-tmux-error.tmp") ]; then
  152. echo ""
  153. echo "Fix"
  154. echo "================================="
  155. if [ ! $(grep "tty:" /etc/group|grep "$(whoami)") ]; then
  156. echo "$(whoami) is not part of the tty group."
  157. fn_script_log_info "$(whoami) is not part of the tty group."
  158. group=$(grep tty /etc/group)
  159. echo ""
  160. echo " ${group}"
  161. fn_script_log_info "${group}"
  162. echo ""
  163. echo "Run the following command with root privileges."
  164. echo ""
  165. echo " usermod -G tty $(whoami)"
  166. echo ""
  167. echo "https://gameservermanagers.com/tmux-op-perm"
  168. fn_script_log_info "https://gameservermanagers.com/tmux-op-perm"
  169. else
  170. echo "No known fix currently. Please log an issue."
  171. fn_script_log_info "No known fix currently. Please log an issue."
  172. echo "https://gameservermanagers.com/support"
  173. fn_script_log_info "https://gameservermanagers.com/support"
  174. fi
  175. fi
  176. fi
  177. core_exit.sh
  178. else
  179. fn_print_ok "${servername}"
  180. fn_script_log_pass "Started ${servername}"
  181. fi
  182. rm "${lgsmlogdir}/.${servicename}-tmux-error.tmp"
  183. echo -en "\n"
  184. }
  185. fn_print_dots "${servername}"
  186. sleep 1
  187. check.sh
  188. fix.sh
  189. info_config.sh
  190. logs.sh
  191. # Will check for updates is updateonstart is yes
  192. if [ "${status}" == "0" ]; then
  193. if [ "${updateonstart}" == "yes" ]||[ "${updateonstart}" == "1" ]||[ "${updateonstart}" == "on" ]; then
  194. exitbypass=1
  195. unset updateonstart
  196. command_update.sh
  197. fi
  198. fi
  199. if [ "${gamename}" == "TeamSpeak 3" ]; then
  200. fn_start_teamspeak3
  201. else
  202. fn_start_tmux
  203. fi
  204. core_exit.sh