4
0

command_start.sh 6.5 KB

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