fn_start 5.3 KB

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