fn_start 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/bin/bash
  2. # LGSM fn_start function
  3. # Author: Daniel Gibbs
  4. # Website: http://danielgibbs.co.uk
  5. # Version: 110415
  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 [ "${tmuxwc}" -eq 0 ]; then
  117. fn_printfailnl "Unable to start ${servername}"
  118. fn_scriptlog "Unable to start ${servername}"
  119. echo -e " Check log files: ${rootdir}/log"
  120. echo -en " Run debug mode: ./${selfname} debug"
  121. if [ -s "${scriptlogdir}/.${servicename}-tmux-error.tmp" ]; then
  122. fn_scriptlog "tmux returned the following error"
  123. cat "${scriptlogdir}/.${servicename}-tmux-error.tmp" >> "${scriptlog}"
  124. fi
  125. else
  126. fn_printok "${servername}"
  127. fn_scriptlog "Started ${servername}"
  128. fi
  129. rm "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  130. sleep 1
  131. echo -en "\n"
  132. }
  133. if [ "${gamename}" == "Teamspeak 3" ]; then
  134. fn_start_teamspeak3
  135. else
  136. fn_start_tmux
  137. fi