command_start.sh 6.7 KB

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