fn_start 5.5 KB

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