fn_startserver 2.0 KB

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