Advertisement
Guest User

Untitled

a guest
May 25th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. set -euo pipefail
  4.  
  5. USER=$(id -u)
  6. XDEBUG_INI_FILE="/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
  7.  
  8. if [[ ${USER} != 0 ]]; then
  9. echo "This script must be run as root"
  10. exit 1
  11. fi
  12.  
  13. function enable {
  14. [[ ! -f ${XDEBUG_INI_FILE} ]] && docker-php-ext-enable xdebug
  15. local HOST=""
  16. local PORT=""
  17.  
  18. while getopts :h:p: OPT; do
  19. case ${OPT} in
  20. h) HOST=$OPTARG ;;
  21. p) PORT=$OPTARG ;;
  22. \?)
  23. echo "Invalid option: -$OPTARG"
  24. exit 1
  25. ;;
  26. :)
  27. echo "Option -$OPTARG requires an argument."
  28. exit 1
  29. ;;
  30. esac
  31. done
  32.  
  33. [ -z ${HOST} ] && HOST=$(ip route | awk '/default/ { print $3 }')
  34. [ -z ${PORT} ] && PORT=9000
  35.  
  36. tee -a ${XDEBUG_INI_FILE} <<EOM
  37. xdebug.remote_host=${HOST}
  38. xdebug.remote_port=${PORT}
  39. xdebug.remote_enable=true
  40. EOM
  41. }
  42.  
  43. function disable {
  44. rm -f ${XDEBUG_INI_FILE}
  45. }
  46.  
  47. function show_status {
  48. if (php -i | grep xdebug | grep 'xdebug.remote_enable => On' &>/dev/null) ; then
  49. echo "Xdebug is enabled"
  50. else
  51. echo "Xdebug is disabled"
  52. fi
  53. }
  54.  
  55. function show_usage {
  56. echo "Usage: xdebug [ enable [-h host] [-p port] | disable | status ]"
  57. echo " 'enable' command can take options -h and -p to set the remote host and port"
  58. echo " 'enable' and 'disable' commands will also reload the php configuration on the fly, no container restart is required"
  59. }
  60.  
  61. function restart_phpfpm {
  62. pkill -USR2 php-fpm
  63. }
  64.  
  65. case "${1-}" in
  66. "enable")
  67. shift
  68. enable "$@"
  69. show_status
  70. restart_phpfpm
  71. ;;
  72. "disable")
  73. disable
  74. show_status
  75. restart_phpfpm
  76. ;;
  77. "status") show_status ;;
  78. *) show_usage ;;
  79. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement