fn_startserver 2.0 KB

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