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