fn_start 5.7 KB

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