command_start.sh 6.7 KB

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