fn_start 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/bash
  2. # LGSM fn_start function
  3. # Author: Daniel Gibbs
  4. # Website: http://danielgibbs.co.uk
  5. # Version: 080214
  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. 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. if [ "${gamename}" == "Counter Strike: Global Offensive" ]; then
  69. startfix=1
  70. fn_csgofix
  71. fi
  72. fn_details_config
  73. fn_parms
  74. fn_logs
  75. fn_printdots "${servername}"
  76. fn_scriptlog "${servername}"
  77. sleep 1
  78. fn_check_tmux
  79. fn_check_steamcmd
  80. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  81. if [ "${tmuxwc}" -eq 0 ]; then
  82. fn_scriptlog "Rotating log files"
  83. if [ "${engine}" == "unreal2" ]; then
  84. mv "${gamelog}" "${gamelogdate}"
  85. fi
  86. mv "${scriptlog}" "${scriptlogdate}"
  87. mv "${consolelog}" "${consolelogdate}"
  88. fi
  89. if [ "${tmuxwc}" -eq 1 ]; then
  90. fn_printinfo "${servername} is already running"
  91. fn_scriptlog "${servername} is already running"
  92. sleep 1
  93. echo -en "\n"
  94. exit
  95. fi
  96. # Create lock file
  97. date > "${rootdir}/${lockselfname}"
  98. cd "${executabledir}"
  99. tmux new-session -d -s ${servicename} "${executable} ${parms}" 2> "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  100. # tmux pipe-pane not supported in tmux versions < 1.6
  101. if [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd [:digit:]|tail -c 3)" -lt "16" ]; then
  102. echo "Console logging disabled: Tmux => 1.6 required" >> "${consolelog}"
  103. echo "Currently installed: $(tmux -V)" >> "${consolelog}"
  104. else
  105. tmux pipe-pane -o -t ${servicename} "exec cat >> '${consolelog}'"
  106. fi
  107. sleep 1
  108. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
  109. if [ "${tmuxwc}" -eq 0 ]; then
  110. fn_printfailnl "Unable to start ${servername}"
  111. fn_scriptlog "Unable to start ${servername}"
  112. echo -en " Check log files: ${rootdir}/log"
  113. if [ -s "${scriptlogdir}/.${servicename}-tmux-error.tmp" ]; then
  114. fn_scriptlog "tmux returned the following error"
  115. cat "${scriptlogdir}/.${servicename}-tmux-error.tmp" >> "${scriptlog}"
  116. fi
  117. else
  118. fn_printok "${servername}"
  119. fn_scriptlog "Started ${servername}"
  120. fi
  121. rm "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  122. sleep 1
  123. echo -en "\n"
  124. }
  125. if [ "${gamename}" == "Teamspeak 3" ]; then
  126. fn_start_teamspeak3
  127. else
  128. fn_start_tmux
  129. fi