mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 04:40:09 +00:00
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:
@@ -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
|
||||
Reference in New Issue
Block a user