fn_startserver 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. # LGSM fn_startserver function
  3. # Author: Daniel Gibbs
  4. # Website: http://danielgibbs.co.uk
  5. # Version: 010115
  6. # Description: Starts the server.
  7. local modulename="Starting"
  8. fn_rootcheck
  9. fn_syscheck
  10. fn_autoip
  11. if [ "${gamename}" == "Counter Strike: Global Offensive" ]; then
  12. startfix=1
  13. fn_csgofix
  14. fi
  15. fn_parms
  16. fn_logmanager
  17. fn_printdots "${servername}"
  18. fn_scriptlog "${servername}"
  19. fn_tmuxcheck
  20. sleep 1
  21. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  22. if [ "${tmuxwc}" -eq 0 ]; then
  23. fn_scriptlog "Rotating log files"
  24. if [ "${engine}" == "unreal2" ]; then
  25. mv "${gamelog}" "${gamelogdate}"
  26. fi
  27. mv "${scriptlog}" "${scriptlogdate}"
  28. mv "${consolelog}" "${consolelogdate}"
  29. fi
  30. if [ "${tmuxwc}" -eq 1 ]; then
  31. fn_printinfo "${servername} is already running"
  32. fn_scriptlog "${servername} is already running"
  33. sleep 1
  34. echo -en "\n"
  35. exit
  36. fi
  37. # Create lock file
  38. date > "${rootdir}/${lockselfname}"
  39. cd "${executabledir}"
  40. tmux new-session -d -s ${servicename} "${executable} ${parms}" 2> "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  41. # tmux pipe-pane not supported in tmux versions < 1.6
  42. if [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd [:digit:]|tail -c 3)" -lt "16" ]; then
  43. echo "Console logging disabled: Tmux => 1.6 required" >> "${consolelog}"
  44. echo "Currently installed: $(tmux -V)" >> "${consolelog}"
  45. else
  46. tmux pipe-pane -o -t ${servicename} "exec cat >> '${consolelog}'"
  47. fi
  48. sleep 1
  49. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
  50. if [ "${tmuxwc}" -eq 0 ]; then
  51. fn_printfailnl "Unable to start ${servername}"
  52. fn_scriptlog "Unable to start ${servername}"
  53. echo -en " Check log files: ${rootdir}/log"
  54. if [ -a "${scriptlogdir}/.${servicename}-tmux-error.tmp" ]; then
  55. fn_scriptlog "tmux returned the following error"
  56. cat "${scriptlogdir}/.${servicename}-tmux-error.tmp" >> "${scriptlog}"
  57. fi
  58. else
  59. fn_printok "${servername}"
  60. fn_scriptlog "Started ${servername}"
  61. fi
  62. rm "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  63. sleep 1
  64. echo -en "\n"