mirror of
https://github.com/lfnovo/open-notebook.git
synced 2026-04-28 19:40:50 +00:00
Users reported "Unable to Connect to API Server" errors on startup because the frontend started before the API finished initialization (database migrations, etc.). - Add wait-for-api.sh script that polls /health endpoint - Update supervisord configs to use wait script instead of sleep 5 - Waits up to 5 minutes for API to be ready before starting frontend - Applies to both single-container and multi-container deployments Fixes #315
22 lines
856 B
Bash
Executable file
22 lines
856 B
Bash
Executable file
#!/bin/bash
|
|
# Wait for the API to be healthy before starting the frontend
|
|
# This prevents the "Unable to Connect to API Server" error during startup
|
|
|
|
API_URL="${INTERNAL_API_URL:-http://localhost:5055}"
|
|
MAX_RETRIES=60 # 60 retries * 5 seconds = 5 minutes max wait
|
|
RETRY_INTERVAL=5
|
|
|
|
echo "Waiting for API to be ready at ${API_URL}/health..."
|
|
|
|
for i in $(seq 1 $MAX_RETRIES); do
|
|
if curl -s -f "${API_URL}/health" > /dev/null 2>&1; then
|
|
echo "API is ready! Starting frontend..."
|
|
exit 0
|
|
fi
|
|
echo "Attempt $i/$MAX_RETRIES: API not ready yet, waiting ${RETRY_INTERVAL}s..."
|
|
sleep $RETRY_INTERVAL
|
|
done
|
|
|
|
echo "ERROR: API did not become ready within $((MAX_RETRIES * RETRY_INTERVAL)) seconds"
|
|
echo "Starting frontend anyway - users may see connection errors initially"
|
|
exit 0 # Exit 0 so frontend still starts (better than nothing)
|