fn_startserver 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. fn_parms
  10. fn_logmanager
  11. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  12. if [ "${tmuxwc}" -eq 0 ]; then
  13. fn_scriptlog "Rotating log files"
  14. if [ "${engine}" == "unreal2" ]; then
  15. mv "${gamelog}" "${gamelogdate}"
  16. fi
  17. mv "${scriptlog}" "${scriptlogdate}"
  18. mv "${consolelog}" "${consolelogdate}"
  19. fi
  20. fn_printdots "Starting ${servicename}: ${servername}"
  21. fn_scriptlog "Starting ${servername}"
  22. sleep 1
  23. if [ "${tmuxwc}" -eq 1 ]; then
  24. fn_printinfo "Starting ${servicename}: ${servername} is already running"
  25. fn_scriptlog "${servername} is already running"
  26. sleep 1
  27. echo -en "\n"
  28. exit
  29. fi
  30. # Create lock file
  31. date > "${rootdir}/${lockselfname}"
  32. cd "${executabledir}"
  33. tmux new-session -d -s ${servicename} "${executable} ${parms}" 2> "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  34. tmux pipe-pane -o -t ${servicename} "exec cat >> '${consolelog}'"
  35. sleep 1
  36. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
  37. if [ "${tmuxwc}" -eq 0 ]; then
  38. fn_printfailnl "Starting ${servicename}: Failed to start ${servername}"
  39. echo -en " Check log files: ${rootdir}/log"
  40. fn_scriptlog "failed to start ${servername}"
  41. if [ -a "${scriptlogdir}/.${servicename}-tmux-error.tmp" ]; then
  42. fn_scriptlog "tmux returned the following error"
  43. cat "${scriptlogdir}/.${servicename}-tmux-error.tmp" >> "${scriptlog}"
  44. fi
  45. else
  46. fn_printok "Starting ${servicename}: ${servername}"
  47. fn_scriptlog "Started ${servername}"
  48. fi
  49. rm "${scriptlogdir}/.${servicename}-tmux-error.tmp"
  50. sleep 1
  51. echo -en "\n"