fn_start 2.0 KB

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