Last active
March 27, 2026 19:36
-
-
Save mrclay/3f2bc74f7ee2ae9fbeba036f7e8fea24 to your computer and use it in GitHub Desktop.
ddev start, but with logging (ctrl-c doesn't stop containers)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| ## Description: Log with colors and despite containers stopped | |
| ## Usage: dclogs [SERVICE] | |
| # | |
| # Create this file as .ddev/commands/host/dclogs | |
| # If in ddev project, use ddev's full config file | |
| if [ -d ".ddev" ]; then | |
| local COMPOSE_ARGS="-f=.ddev/.ddev-docker-compose-full.yaml" | |
| else | |
| local COMPOSE_ARGS="" | |
| fi | |
| while : | |
| do | |
| # Intentionally not quoting $COMPOSE_ARGS and $1 | |
| docker compose $COMPOSE_ARGS logs -f --tail=3 $1 | |
| [ $? -eq 0 ] || break | |
| echo "Awaiting a container to restart" | |
| sleep 5 | |
| # wait around for startup | |
| while : | |
| do | |
| # Intentionally not quoting $COMPOSE_ARGS | |
| local DCTOP=$(docker compose $COMPOSE_ARGS top 2> /dev/null) | |
| if [[ "$DCTOP" =~ "PID" ]]; then | |
| # we're in business | |
| break | |
| else | |
| sleep 2 | |
| fi | |
| done | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| ## Description: start with logging (with optional service) | |
| ## Usage: start-logs [SERVICE] | |
| # | |
| # Create this file as .ddev/commands/host/start-logs | |
| service="${1:-}" | |
| # Set monitor mode to allow job control (fg) | |
| set -m | |
| trap "kill ${LOG_PID} 2>/dev/null" EXIT | |
| # Start dclogs in background, then start, finally foreground dclogs. | |
| ddev dclogs "${service}" & | |
| LOG_PID=$! | |
| ddev start | |
| echo '' # just for the newline | |
| fg %1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment