fn_start 5.7 KB

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