command_start.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #!/bin/bash
  2. # LGSM 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_check_is_in_tmux(){
  11. if [ -n "${TMUX}" ];then
  12. fn_print_fail_nl "tmuxception error: Sorry Cobb you cannot start a tmux session inside of a tmux session."
  13. fn_script_log_fatal "tmuxception error: Attempted to start a tmux session inside of a tmux session."
  14. fn_print_information_nl "LGSM creates a tmux session when starting the server."
  15. echo "It is not possible to run a tmux session inside another tmux session"
  16. echo "https://github.com/GameServerManagers/LinuxGSM/wiki/Tmux#tmuxception"
  17. core_exit.sh
  18. fi
  19. }
  20. fn_check_is_in_screen(){
  21. if [ "$TERM" == "screen" ];then
  22. fn_print_fail_nl "tmuxception error: Sorry Cobb you cannot start a tmux session inside of a screen session."
  23. fn_script_log_fatal "tmuxception error: Attempted to start a tmux session inside of a screen session."
  24. fn_print_information_nl "LGSM creates a tmux session when starting the server."
  25. echo "It is not possible to run a tmux session inside screen session"
  26. echo "https://github.com/GameServerManagers/LinuxGSM/wiki/Tmux#tmuxception"
  27. core_exit.sh
  28. fi
  29. }
  30. fn_start_teamspeak3(){
  31. if [ ! -e "${servercfgfullpath}" ]; then
  32. fn_print_warn_nl "${servercfgfullpath} is missing"
  33. fn_script_log_warn "${servercfgfullpath} is missing"
  34. echo " * Creating blank ${servercfg}"
  35. fn_script_log_info "Creating blank ${servercfg}"
  36. sleep 2
  37. echo " * ${servercfg} can remain blank by default."
  38. fn_script_log_info "${servercfgfullpath} can remain blank by default."
  39. sleep 2
  40. echo " * ${servercfg} is located in ${servercfgfullpath}."
  41. fn_script_log_info "${servercfg} is located in ${servercfgfullpath}."
  42. sleep 5
  43. touch "${servercfgfullpath}"
  44. fi
  45. sleep 1
  46. check_status.sh
  47. if [ "${status}" != "0" ]; then
  48. fn_print_info_nl "${servername} is already running"
  49. fn_script_log_error "${servername} is already running"
  50. core_exit.sh
  51. fi
  52. mv "${scriptlog}" "${scriptlogdate}"
  53. # Create lock file
  54. date > "${rootdir}/${lockselfname}"
  55. cd "${executabledir}"
  56. if [ "${ts3serverpass}" == "1" ];then
  57. ./ts3server_startscript.sh start serveradmin_password="${newpassword}" inifile="${servercfgfullpath}"
  58. else
  59. ./ts3server_startscript.sh start inifile="${servercfgfullpath}" > /dev/null 2>&1
  60. fi
  61. sleep 1
  62. check_status.sh
  63. if [ "${status}" == "0" ]; then
  64. fn_print_fail_nl "Unable to start ${servername}"
  65. fn_script_log_fatal "Unable to start ${servername}"
  66. echo -e " Check log files: ${rootdir}/log"
  67. core_exit.sh
  68. else
  69. fn_print_ok_nl "${servername}"
  70. fn_script_log_pass "Started ${servername}"
  71. fi
  72. }
  73. fn_start_tmux(){
  74. fn_parms
  75. # Log rotation
  76. check_status.sh
  77. if [ "${status}" == "0" ]; then
  78. fn_script_log_info "Rotating log files"
  79. if [ "${engine}" == "unreal2" ]; then
  80. if [ -f "${gamelog}" ]; then
  81. mv "${gamelog}" "${gamelogdate}"
  82. fi
  83. fi
  84. mv "${scriptlog}" "${scriptlogdate}"
  85. mv "${consolelog}" "${consolelogdate}"
  86. fi
  87. # If server is already running exit
  88. check_status.sh
  89. if [ "${status}" != "0" ]; then
  90. fn_print_info_nl "${servername} is already running"
  91. fn_script_log_error "${servername} is already running"
  92. core_exit.sh
  93. fi
  94. # Create lock file
  95. date > "${rootdir}/${lockselfname}"
  96. cd "${executabledir}"
  97. tmux new-session -d -s "${servicename}" "${executable} ${parms}" 2> "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  98. # tmux pipe-pane not supported in tmux versions < 1.6
  99. if [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd '[:digit:]')" -lt "16" ]; then
  100. echo "Console logging disabled: Tmux => 1.6 required" >> "${consolelog}"
  101. echo "https://gameservermanagers.com/tmux-upgrade" >> "${consolelog}"
  102. echo "Currently installed: $(tmux -V)" >> "${consolelog}"
  103. # Console logging disabled: Bug in tmux 1.8 breaks logging
  104. elif [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd '[:digit:]')" -eq "18" ]; then
  105. echo "Console logging disabled: Bug in tmux 1.8 breaks logging" >> "${consolelog}"
  106. echo "https://gameservermanagers.com/tmux-upgrade" >> "${consolelog}"
  107. echo "Currently installed: $(tmux -V)" >> "${consolelog}"
  108. # Console logging enable or not set
  109. elif [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then
  110. touch "${consolelog}"
  111. tmux pipe-pane -o -t "${servicename}" "exec cat >> '${consolelog}'"
  112. # Console logging disabled
  113. elif [ "${consolelogging}" == "off" ]; then
  114. touch "${consolelog}"
  115. cat "Console logging disabled by user" >> "{consolelog}"
  116. fn_script_log_info "Console logging disabled by user"
  117. fi
  118. sleep 1
  119. # If the server fails to start
  120. check_status.sh
  121. if [ "${status}" == "0" ]; then
  122. fn_print_fail_nl "Unable to start ${servername}"
  123. fn_script_log_fatal "Unable to start ${servername}"
  124. sleep 1
  125. if [ -s "${scriptlogdir}/.${servicename}-tmux-error.tmp" ]; then
  126. fn_print_fail_nl "Unable to start ${servername}: Tmux error:"
  127. fn_script_log_fatal "Unable to start ${servername}: Tmux error:"
  128. echo ""
  129. echo "Command"
  130. echo "================================="
  131. echo "tmux new-session -d -s \"${servicename}\" \"${executable} ${parms}\"" | tee -a "${scriptlog}"
  132. echo ""
  133. echo "Error"
  134. echo "================================="
  135. cat "${scriptlogdir}/.${servicename}-tmux-error.tmp" | tee -a "${scriptlog}"
  136. # Detected error https://gameservermanagers.com/issues
  137. if [ $(grep -c "Operation not permitted" "${scriptlogdir}/.${servicename}-tmux-error.tmp") ]; then
  138. echo ""
  139. echo "Fix"
  140. echo "================================="
  141. if [ ! $(grep "tty:" /etc/group|grep "$(whoami)") ]; then
  142. echo "$(whoami) is not part of the tty group."
  143. fn_script_log_info "$(whoami) is not part of the tty group."
  144. group=$(grep tty /etc/group)
  145. echo ""
  146. echo " ${group}"
  147. fn_script_log_info "${group}"
  148. echo ""
  149. echo "Run the following command with root privileges."
  150. echo ""
  151. echo " usermod -G tty $(whoami)"
  152. echo ""
  153. echo "https://gameservermanagers.com/tmux-op-perm"
  154. fn_script_log_info "https://gameservermanagers.com/tmux-op-perm"
  155. else
  156. echo "No known fix currently. Please log an issue."
  157. fn_script_log_info "No known fix currently. Please log an issue."
  158. echo "https://gameservermanagers.com/issues"
  159. fn_script_log_info "https://gameservermanagers.com/issues"
  160. fi
  161. fi
  162. fi
  163. core_exit.sh
  164. else
  165. fn_print_ok "${servername}"
  166. fn_script_log_pass "Started ${servername}"
  167. fi
  168. rm "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  169. echo -en "\n"
  170. }
  171. fn_print_dots "${servername}"
  172. sleep 1
  173. fn_check_is_in_tmux
  174. fn_check_is_in_screen
  175. check.sh
  176. fix.sh
  177. info_config.sh
  178. logs.sh
  179. # Will check for updates is updateonstart is yes
  180. if [ "${status}" == "0" ]; then
  181. if [ "${updateonstart}" == "yes" ]||[ "${updateonstart}" == "1" ]||[ "${updateonstart}" == "on" ]; then
  182. exitbypass=1
  183. command_update.sh
  184. fi
  185. fi
  186. if [ "${gamename}" == "TeamSpeak 3" ]; then
  187. fn_start_teamspeak3
  188. else
  189. fn_start_tmux
  190. fi
  191. core_exit.sh