command_start.sh 5.8 KB

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