fn_startserver 2.0 KB

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