command_start.sh 5.6 KB

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