#!/bin/sh set -eu WAIT_RETRIES="${WAIT_RETRIES:-60}" WAIT_INTERVAL_SECONDS="${WAIT_INTERVAL_SECONDS:-2}" wait_for_service() { label="$1" host="$2" port="$3" python - "$label" "$host" "$port" "$WAIT_RETRIES" "$WAIT_INTERVAL_SECONDS" <<'PY' import socket import sys import time label, host, port, retries, interval = sys.argv[1], sys.argv[2], int(sys.argv[3]), int(sys.argv[4]), float(sys.argv[5]) for attempt in range(1, retries + 1): try: socket.getaddrinfo(host, port, type=socket.SOCK_STREAM) with socket.create_connection((host, port), timeout=2): print(f"[docker-entrypoint] {label} ready at {host}:{port}") raise SystemExit(0) except OSError as exc: print( f"[docker-entrypoint] waiting for {label} ({attempt}/{retries}) at {host}:{port}: {exc}", file=sys.stderr, ) time.sleep(interval) print(f"[docker-entrypoint] {label} never became reachable at {host}:{port}", file=sys.stderr) raise SystemExit(1) PY } wait_for_service "database" "${DB_HOST:-127.0.0.1}" "${DB_PORT:-3306}" wait_for_service "redis" "${CHANNEL_REDIS_HOST:-127.0.0.1}" "${CHANNEL_REDIS_PORT:-6379}" python manage.py migrate --noinput exec python manage.py runserver 0.0.0.0:8000