command_start.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #!/bin/bash
  2. # LGSM command_start.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. lgsm_version="060516"
  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_scriptlog "${servercfgfullpath} is missing"
  13. echo " * Creating blank ${servercfg}"
  14. fn_scriptlog "Creating blank ${servercfg}"
  15. sleep 2
  16. echo " * ${servercfg} can remain blank by default."
  17. fn_scriptlog "${servercfgfullpath} can remain blank by default."
  18. sleep 2
  19. echo " * ${servercfg} is located in ${servercfgfullpath}."
  20. fn_scriptlog "${servercfg} is located in ${servercfgfullpath}."
  21. sleep 5
  22. touch "${servercfgfullpath}"
  23. fi
  24. fn_print_dots "${servername}"
  25. fn_scriptlog "${servername}"
  26. sleep 1
  27. check_status.sh
  28. if [ "${status}" != "0" ]; then
  29. fn_print_info_nl "${servername} is already running"
  30. fn_scriptlog "${servername} is already running"
  31. exit
  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_scriptlog "Unable to start ${servername}"
  47. echo -e " Check log files: ${rootdir}/log"
  48. exit 1
  49. else
  50. fn_print_ok_nl "${servername}"
  51. fn_scriptlog "Started ${servername}"
  52. fi
  53. }
  54. fn_start_tmux(){
  55. fn_parms
  56. fn_print_dots "${servername}"
  57. fn_scriptlog "${servername}"
  58. sleep 1
  59. # Log rotation
  60. check_status.sh
  61. if [ "${status}" == "0" ]; then
  62. fn_scriptlog "Rotating log files"
  63. if [ "${engine}" == "unreal2" ]; then
  64. mv "${gamelog}" "${gamelogdate}"
  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_scriptlog "${servername} is already running"
  74. exit
  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_scriptlog "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_scriptlog "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_scriptlog "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_scriptlog "$(whoami) is not part of the tty group."
  126. group=$(grep tty /etc/group)
  127. echo ""
  128. echo " ${group}"
  129. fn_scriptlog "${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_scriptlog "https://gameservermanagers.com/tmux-op-perm"
  137. else
  138. echo "No known fix currently. Please log an issue."
  139. fn_scriptlog "No known fix currently. Please log an issue."
  140. echo "https://gameservermanagers.com/issues"
  141. fn_scriptlog "https://gameservermanagers.com/issues"
  142. fi
  143. fi
  144. fi
  145. exit 1
  146. else
  147. fn_print_ok "${servername}"
  148. fn_scriptlog "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