Skip to content

Commit 035a83f

Browse files
committed
debug: improve entrypoint logging for troubleshooting
1 parent ec8b331 commit 035a83f

1 file changed

Lines changed: 28 additions & 29 deletions

File tree

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,55 @@
11
#!/bin/bash
22
set -e
33

4-
echo " ProStaff API - Starting..."
5-
6-
# Skip DATABASE_URL encoding - handled by Rails initializer
7-
# The initializer (config/initializers/database_url_override.rb) will detect
8-
# special characters and parse manually in database.yml
9-
echo " Database configuration will be handled by Rails initializer"
4+
echo "========================================" >&2
5+
echo "ProStaff API - Docker Entrypoint" >&2
6+
echo "========================================" >&2
107

118
# Remove any pre-existing server PID file
9+
echo "[1/4] Removing stale PID files..." >&2
1210
rm -f /app/tmp/pids/server.pid
1311

1412
# Wait for database to be ready
15-
echo " Waiting for database..."
16-
# Use SUPABASE_DB_URL or DATABASE_URL, extract host for pg_isready
13+
echo "[2/4] Checking database connection..." >&2
1714
DB_URL="${SUPABASE_DB_URL:-$DATABASE_URL}"
1815
if [ -n "$DB_URL" ]; then
1916
# Extract host and port from URL (format: postgresql://user:pass@host:port/db)
2017
# Parse from right to left to handle @ in password
2118
DB_HOST=$(echo "$DB_URL" | sed -E 's|.*@([^@/]+):[0-9]+/.*|\1|')
2219
DB_PORT=$(echo "$DB_URL" | sed -E 's|.*@[^@/]+:([0-9]+)/.*|\1|')
2320

24-
echo " Checking connection to ${DB_HOST}:${DB_PORT}..."
21+
echo " → Host: ${DB_HOST}:${DB_PORT}" >&2
22+
23+
MAX_RETRIES=30
24+
RETRY_COUNT=0
2525
until pg_isready -h "$DB_HOST" -p "$DB_PORT" > /dev/null 2>&1; do
26-
echo " Database is unavailable - sleeping"
26+
RETRY_COUNT=$((RETRY_COUNT + 1))
27+
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
28+
echo " ✗ Database connection timeout after ${MAX_RETRIES} attempts" >&2
29+
exit 1
30+
fi
31+
echo " ⏳ Waiting for database (attempt ${RETRY_COUNT}/${MAX_RETRIES})..." >&2
2732
sleep 2
2833
done
34+
echo " ✓ Database is ready" >&2
2935
else
30-
until PGPASSWORD=$POSTGRES_PASSWORD psql -h "${POSTGRES_HOST:-postgres}" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c '\q' 2>/dev/null; do
31-
echo " Database is unavailable - sleeping"
32-
sleep 2
33-
done
36+
echo " ⚠ No DATABASE_URL configured, skipping database check" >&2
3437
fi
35-
echo " Database is ready"
3638

3739
# Run database migrations
38-
echo " Running database migrations..."
39-
bundle exec rails db:migrate 2>/dev/null || {
40-
echo " Migration failed, attempting to create database..."
41-
bundle exec rails db:create
42-
bundle exec rails db:migrate
43-
}
44-
45-
# Preload app for better performance
46-
if [ "$RAILS_ENV" = "production" ]; then
47-
echo " Preloading application..."
48-
bundle exec rails runner 'Rails.application.eager_load!'
40+
echo "[3/4] Running database migrations..." >&2
41+
if bundle exec rails db:migrate 2>&1 | tee /tmp/migration.log >&2; then
42+
echo " ✓ Migrations completed" >&2
43+
else
44+
echo " ⚠ Migration failed, check output above" >&2
45+
echo " → Attempting to create database..." >&2
46+
bundle exec rails db:create 2>&1 | tee -a /tmp/migration.log >&2
47+
bundle exec rails db:migrate 2>&1 | tee -a /tmp/migration.log >&2
4948
fi
5049

51-
echo " Application ready!"
52-
53-
echo " Starting application server..."
50+
# Skip preload in production - Puma will handle it
51+
echo "[4/4] Starting application server..." >&2
52+
echo "========================================" >&2
5453

5554
# Execute the main command
5655
exec "$@"

0 commit comments

Comments
 (0)