4
0

command_debug.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/bin/bash
  2. # LinuxGSM command_debug.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Runs the server without tmux and directly from the terminal.
  7. commandname="DEBUG"
  8. commandaction="Debugging"
  9. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. fn_firstcommand_set
  11. # Trap to remove lockfile on quit.
  12. fn_lockfile_trap() {
  13. # Remove lockfile.
  14. rm -f "${lockdir:?}/${selfname}-started.lock"
  15. # resets terminal. Servers can sometimes mess up the terminal on exit.
  16. reset
  17. fn_print_dots "Stopping debug"
  18. fn_print_ok_nl "Stopping debug"
  19. fn_script_log_pass "Stopping debug"
  20. # remove trap.
  21. trap - INT
  22. core_exit.sh
  23. }
  24. fn_print_header
  25. check.sh
  26. fix.sh
  27. info_distro.sh
  28. info_game.sh
  29. {
  30. echo -e "${lightblue}Distro:\t\t${default}${distroname}"
  31. echo -e "${lightblue}Architecture:\t\t${default}${arch}"
  32. echo -e "${lightblue}Kernel:\t\t${default}${kernel}"
  33. echo -e "${lightblue}Hostname:\t\t${default}${HOSTNAME}"
  34. echo -e "${lightblue}tmux:\t\t${default}${tmuxversion}"
  35. echo -e "${lightblue}Avg Load:\t\t${default}${load}"
  36. echo -e "${lightblue}Free Memory:\t\t${default}${physmemfree}"
  37. echo -e "${lightblue}Free Disk:\t\t${default}${availspace}"
  38. } | column -s $'\t' -t
  39. # glibc required.
  40. if [ -n "${glibc}" ]; then
  41. if [ "${glibc}" == "null" ]; then
  42. # Glibc is not required.
  43. :
  44. elif [ -z "${glibc}" ]; then
  45. echo -e "${lightblue}glibc required:\t${red}UNKNOWN${default}"
  46. elif [ "$(printf '%s\n' "${glibc}" "${glibcversion}" | sort -V | head -n 1)" != "${glibc}" ]; then
  47. echo -e "${lightblue}glibc required:\t${red}${glibc} ${default}(${red}distro glibc ${glibcversion} too old${default})"
  48. else
  49. echo -e "${lightblue}glibc required:\t${green}${glibc}${default}"
  50. fi
  51. fi
  52. # Server IP.
  53. echo -e "${lightblue}Game Server IP:\t${default}${ip}:${port}"
  54. # External server IP.
  55. if [ "${publicip}" ]; then
  56. if [ "${ip}" != "${publicip}" ]; then
  57. echo -e "${lightblue}Internet IP:\t${default}${publicip}:${port}"
  58. fi
  59. fi
  60. # Server password.
  61. if [ "${serverpassword}" ]; then
  62. echo -e "${lightblue}Server password:\t${default}${serverpassword}"
  63. fi
  64. fn_reload_startparameters
  65. if [ -n "${variantstartparameters}" ]; then
  66. startparameters="${variantstartparameters} ${startparameters}"
  67. fi
  68. if [ -n "${variantbasepath}" ]; then
  69. startparameters="${startparameters} +set fs_basepath ${variantbasepath}"
  70. fi
  71. echo -e "${lightblue}Start parameters:${default}"
  72. if [ "${engine}" == "source" ] || [ "${engine}" == "goldsrc" ]; then
  73. echo -e "${executable} ${startparameters} -debug"
  74. elif [ "${engine}" == "quake" ]; then
  75. echo -e "${executable} ${startparameters} -condebug"
  76. else
  77. echo -e "${preexecutable} ${executable} ${startparameters}"
  78. fi
  79. echo -e ""
  80. echo -e "Use debug for identifying server issues only!"
  81. echo -e "Press CTRL+c to drop out of debug mode."
  82. fn_print_warning_nl "If ${selfname} is already running it will be stopped."
  83. if ! fn_prompt_yn "Continue?" Y; then
  84. exitcode=0
  85. core_exit.sh
  86. fi
  87. fn_print_info_nl "Stopping any running servers"
  88. fn_script_log_info "Stopping any running servers"
  89. exitbypass=1
  90. command_stop.sh
  91. fn_firstcommand_reset
  92. unset exitbypass
  93. fn_print_dots "Starting debug"
  94. fn_script_log_info "Starting debug"
  95. fn_print_ok_nl "Starting debug"
  96. # Create started lockfile.
  97. date '+%s' > "${lockdir:?}/${selfname}-started.lock"
  98. echo "${version}" >> "${lockdir}/${selfname}-started.lock"
  99. echo "${port}" >> "${lockdir}/${selfname}-started.lock"
  100. fn_script_log_info "Lockfile generated"
  101. fn_script_log_info "${lockdir}/${selfname}-started.lock"
  102. if [ "${shortname}" == "av" ]; then
  103. cd "${systemdir}" || exit
  104. else
  105. cd "${executabledir}" || exit
  106. fi
  107. # Note: do not add double quotes to ${executable} ${startparameters}.
  108. if [ "${engine}" == "source" ] || [ "${engine}" == "goldsrc" ]; then
  109. eval "${executable} ${startparameters} -debug"
  110. elif [ "${engine}" == "quake" ]; then
  111. eval "${executable} ${startparameters} -condebug"
  112. else
  113. # shellcheck disable=SC2086
  114. eval "${preexecutable} ${executable} ${startparameters}"
  115. fi
  116. exitcode=$?
  117. if [ "${exitcode}" -ne 0 ]; then
  118. fn_print_error_nl "Server has stopped: exit code: ${exitcode}"
  119. fn_script_log_error "Server has stopped: exit code: ${exitcode}"
  120. fn_print_error_nl "Press ENTER to exit debug mode"
  121. read -r
  122. else
  123. fn_print_ok_nl "Server has stopped"
  124. fn_script_log_pass "Server has stopped"
  125. fn_print_ok_nl "Press ENTER to exit debug mode"
  126. read -r
  127. fi
  128. fn_lockfile_trap
  129. fn_print_dots "Stopping debug"
  130. fn_print_ok_nl "Stopping debug"
  131. fn_script_log_info "Stopping debug"
  132. core_exit.sh