fn_startserver 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. # LGSM fn_startserver function
  3. # Author: Daniel Gibbs
  4. # Website: http://danielgibbs.co.uk
  5. # Version: 011214
  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 -o -t ${servicename} "exec cat >> '${consolelog}'"
  39. sleep 1
  40. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
  41. if [ "${tmuxwc}" -eq 0 ]; then
  42. fn_printfailnl "Starting ${servicename}: Failed to start ${servername}"
  43. echo -en " Check log files: ${rootdir}/log"
  44. fn_scriptlog "failed to start ${servername}"
  45. if [ -a "${scriptlogdir}/.${servicename}-tmux-error.tmp" ]; then
  46. fn_scriptlog "tmux returned the following error"
  47. cat "${scriptlogdir}/.${servicename}-tmux-error.tmp" >> "${scriptlog}"
  48. fi
  49. else
  50. fn_printok "Starting ${servicename}: ${servername}"
  51. fn_scriptlog "Started ${servername}"
  52. fi
  53. rm "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  54. sleep 1
  55. echo -en "\n"