command_start.sh 6.1 KB

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