command_start.sh 5.9 KB

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