command_start.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #!/bin/bash
  2. # LGSM command_start.sh function
  3. # Author: Daniel Gibbs
  4. # Website: http://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_print_dots "${servername}"
  56. fn_scriptlog "${servername}"
  57. sleep 1
  58. # Log rotation
  59. check_status.sh
  60. if [ "${status}" == "0" ]; then
  61. fn_scriptlog "Rotating log files"
  62. if [ "${engine}" == "unreal2" ]; then
  63. mv "${gamelog}" "${gamelogdate}"
  64. fi
  65. mv "${scriptlog}" "${scriptlogdate}"
  66. mv "${consolelog}" "${consolelogdate}"
  67. fi
  68. # If server is already running exit
  69. check_status.sh
  70. if [ "${status}" != "0" ]; then
  71. fn_print_info_nl "${servername} is already running"
  72. fn_scriptlog "${servername} is already running"
  73. exit
  74. fi
  75. # Create lock file
  76. date > "${rootdir}/${lockselfname}"
  77. cd "${executabledir}"
  78. tmux new-session -d -s "${servicename}" "${executable} ${parms}" 2> "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  79. # tmux pipe-pane not supported in tmux versions < 1.6
  80. if [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd '[:digit:]')" -lt "16" ]; then
  81. echo "Console logging disabled: Tmux => 1.6 required" >> "${consolelog}"
  82. echo "http://gameservermanagers.com/tmux-upgrade" >> "${consolelog}"
  83. echo "Currently installed: $(tmux -V)" >> "${consolelog}"
  84. # Console logging disabled: Bug in tmux 1.8 breaks logging
  85. elif [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd '[:digit:]')" -eq "18" ]; then
  86. echo "Console logging disabled: Bug in tmux 1.8 breaks logging" >> "${consolelog}"
  87. echo "http://gameservermanagers.com/tmux-upgrade" >> "${consolelog}"
  88. echo "Currently installed: $(tmux -V)" >> "${consolelog}"
  89. # Console logging enable or not set
  90. elif [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then
  91. touch "${consolelog}"
  92. tmux pipe-pane -o -t "${servicename}" "exec cat >> '${consolelog}'"
  93. # Console logging disabled
  94. elif [ "${consolelogging}" == "off" ]; then
  95. touch "${consolelog}"
  96. cat "Console logging disabled by user" >> "{consolelog}"
  97. fn_scriptlog "Console logging disabled by user"
  98. fi
  99. sleep 1
  100. # If the server fails to start
  101. check_status.sh
  102. if [ "${status}" == "0" ]; then
  103. fn_print_fail_nl "Unable to start ${servername}"
  104. fn_scriptlog "Unable to start ${servername}"
  105. sleep 1
  106. if [ -s "${scriptlogdir}/.${servicename}-tmux-error.tmp" ]; then
  107. fn_print_fail_nl "Unable to start ${servername}: Tmux error:"
  108. fn_scriptlog "Tmux error"
  109. echo ""
  110. echo "Command"
  111. echo "================================="
  112. echo "tmux new-session -d -s \"${servicename}\" \"${executable} ${parms}\"" | tee -a "${scriptlog}"
  113. echo ""
  114. echo "Error"
  115. echo "================================="
  116. cat "${scriptlogdir}/.${servicename}-tmux-error.tmp" | tee -a "${scriptlog}"
  117. # Detected error http://gameservermanagers.com/issues
  118. if [ $(grep -c "Operation not permitted" "${scriptlogdir}/.${servicename}-tmux-error.tmp") ]; then
  119. echo ""
  120. echo "Fix"
  121. echo "================================="
  122. if [ ! $(grep "tty:" /etc/group|grep "$(whoami)") ]; then
  123. echo "$(whoami) is not part of the tty group."
  124. fn_scriptlog "$(whoami) is not part of the tty group."
  125. group=$(grep tty /etc/group)
  126. echo ""
  127. echo " ${group}"
  128. fn_scriptlog "${group}"
  129. echo ""
  130. echo "Run the following command with root privileges."
  131. echo ""
  132. echo " usermod -G tty $(whoami)"
  133. echo ""
  134. echo "http://gameservermanagers.com/tmux-op-perm"
  135. fn_scriptlog "http://gameservermanagers.com/tmux-op-perm"
  136. else
  137. echo "No known fix currently. Please log an issue."
  138. fn_scriptlog "No known fix currently. Please log an issue."
  139. echo "http://gameservermanagers.com/issues"
  140. fn_scriptlog "http://gameservermanagers.com/issues"
  141. fi
  142. fi
  143. fi
  144. exit 1
  145. else
  146. fn_print_ok "${servername}"
  147. fn_scriptlog "Started ${servername}"
  148. fi
  149. rm "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  150. echo -en "\n"
  151. }
  152. check.sh
  153. fix.sh
  154. info_config.sh
  155. fn_parms
  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