fix: Add support for external PostgreSQL and Redis instances

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
This commit is contained in:
Joe Harrison
2026-02-12 15:04:09 +00:00
parent eca24e46a8
commit 7addb1dc70
6 changed files with 220 additions and 75 deletions
+39
View File
@@ -0,0 +1,39 @@
#!/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