Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- set -euo pipefail
- USER=$(id -u)
- XDEBUG_INI_FILE="/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
- if [[ ${USER} != 0 ]]; then
- echo "This script must be run as root"
- exit 1
- fi
- function enable {
- [[ ! -f ${XDEBUG_INI_FILE} ]] && docker-php-ext-enable xdebug
- local HOST=""
- local PORT=""
- while getopts :h:p: OPT; do
- case ${OPT} in
- h) HOST=$OPTARG ;;
- p) PORT=$OPTARG ;;
- \?)
- echo "Invalid option: -$OPTARG"
- exit 1
- ;;
- :)
- echo "Option -$OPTARG requires an argument."
- exit 1
- ;;
- esac
- done
- [ -z ${HOST} ] && HOST=$(ip route | awk '/default/ { print $3 }')
- [ -z ${PORT} ] && PORT=9000
- tee -a ${XDEBUG_INI_FILE} <<EOM
- xdebug.remote_host=${HOST}
- xdebug.remote_port=${PORT}
- xdebug.remote_enable=true
- EOM
- }
- function disable {
- rm -f ${XDEBUG_INI_FILE}
- }
- function show_status {
- if (php -i | grep xdebug | grep 'xdebug.remote_enable => On' &>/dev/null) ; then
- echo "Xdebug is enabled"
- else
- echo "Xdebug is disabled"
- fi
- }
- function show_usage {
- echo "Usage: xdebug [ enable [-h host] [-p port] | disable | status ]"
- echo " 'enable' command can take options -h and -p to set the remote host and port"
- echo " 'enable' and 'disable' commands will also reload the php configuration on the fly, no container restart is required"
- }
- function restart_phpfpm {
- pkill -USR2 php-fpm
- }
- case "${1-}" in
- "enable")
- shift
- enable "$@"
- show_status
- restart_phpfpm
- ;;
- "disable")
- disable
- show_status
- restart_phpfpm
- ;;
- "status") show_status ;;
- *) show_usage ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement