command_start.sh 5.8 KB

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