mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 21:00:09 +00:00
7addb1dc70
Implements smart detection that allows users to provide external DATABASE_URL or REDIS_URL. When external services are detected, internal instances are automatically disabled to save resources. Maintains full backward compatibility with existing setup
40 lines
1.3 KiB
Bash
40 lines
1.3 KiB
Bash
#!/bin/bash
|
|
# PostgreSQL startup wrapper for unified container
|
|
# Smart supervisor: detects external PostgreSQL and sleeps instead of starting local instance
|
|
#
|
|
# Behavior:
|
|
# - If DATABASE_URL points to external host (not 127.0.0.1/localhost), sleep infinity
|
|
# - Otherwise, start local PostgreSQL instance
|
|
|
|
set -e
|
|
|
|
# Load environment from /etc/environment (set by entrypoint)
|
|
if [ -f /etc/environment ]; then
|
|
set -a
|
|
source /etc/environment
|
|
set +a
|
|
fi
|
|
|
|
echo "[PostgreSQL] Checking for external database configuration..."
|
|
|
|
# Extract host from DATABASE_URL
|
|
# Format: postgresql://user:pass@host:port/db
|
|
if [ -n "$DATABASE_URL" ]; then
|
|
# Extract the host part (between @ and :port or /)
|
|
DB_HOST=$(echo "$DATABASE_URL" | sed -n 's|.*@\([^:/]*\).*|\1|p')
|
|
|
|
echo "[PostgreSQL] Detected DATABASE_URL host: $DB_HOST"
|
|
|
|
# Check if host is external (not localhost or 127.0.0.1)
|
|
if [ "$DB_HOST" != "127.0.0.1" ] && [ "$DB_HOST" != "localhost" ]; then
|
|
echo "[PostgreSQL] ✅ External PostgreSQL detected at $DB_HOST"
|
|
echo "[PostgreSQL] Skipping local PostgreSQL startup - sleeping to keep supervisord happy"
|
|
exec sleep infinity
|
|
fi
|
|
fi
|
|
|
|
echo "[PostgreSQL] Starting local PostgreSQL server..."
|
|
|
|
# Start PostgreSQL as postgres user
|
|
exec /usr/lib/postgresql/16/bin/postgres -D /var/lib/postgresql/data
|