fn_start 5.4 KB

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