command_start.sh 5.9 KB

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