fn_start 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/bin/bash
  2. # LGSM fn_start function
  3. # Author: Daniel Gibbs
  4. # Website: http://danielgibbs.co.uk
  5. # Version: 160214
  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. #
  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 -en " Check log files: ${rootdir}/log"
  57. echo -en " Run debug mode: ./${selfname} debug"
  58. else
  59. fn_printok "${servername}"
  60. fn_scriptlog "Started ${servername}"
  61. fi
  62. sleep 0.5
  63. echo -en "\n"
  64. }
  65. fn_start_tmux(){
  66. fn_check_root
  67. fn_check_systemdir
  68. fn_check_ip
  69. fn_check_logs
  70. if [ "${gamename}" == "Counter Strike: Global Offensive" ]; then
  71. startfix=1
  72. fn_csgofix
  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. # 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 [ "${tmuxwc}" -eq 0 ]; then
  116. fn_printfailnl "Unable to start ${servername}"
  117. fn_scriptlog "Unable to start ${servername}"
  118. echo -en " Check log files: ${rootdir}/log"
  119. echo -en " Run debug mode: ./${selfname} debug"
  120. if [ -s "${scriptlogdir}/.${servicename}-tmux-error.tmp" ]; then
  121. fn_scriptlog "tmux returned the following error"
  122. cat "${scriptlogdir}/.${servicename}-tmux-error.tmp" >> "${scriptlog}"
  123. fi
  124. else
  125. fn_printok "${servername}"
  126. fn_scriptlog "Started ${servername}"
  127. fi
  128. rm "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  129. sleep 1
  130. echo -en "\n"
  131. }
  132. if [ "${gamename}" == "Teamspeak 3" ]; then
  133. fn_start_teamspeak3
  134. else
  135. fn_start_tmux
  136. fi