fix(entrypoint): fail-fast if Flask does not bind within timeout instead of silently starting Caddy with no backend

This commit is contained in:
2026-05-10 01:51:09 -04:00
parent d4f391bab1
commit 255ccebf29
2 changed files with 14 additions and 8 deletions

View File

@@ -68,17 +68,20 @@ cat > /etc/caddy/Caddyfile <<EOF
EOF
python3 /opt/server.py &
FLASK_PID=$!
# Wait for Flask to be ready before handing off to Caddy
python3 -c "
import socket, time
for _ in range(40):
import socket, sys, time
for _ in range(80):
try:
s = socket.create_connection(('127.0.0.1', 8080), timeout=0.25)
s.close()
break
sys.exit(0)
except OSError:
time.sleep(0.1)
"
print('Flask did not bind to :8080 in time', file=sys.stderr)
sys.exit(1)
" || { echo 'Flask startup failed — aborting'; kill $FLASK_PID 2>/dev/null; exit 1; }
exec caddy run --config /etc/caddy/Caddyfile