command_start.sh 6.3 KB

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