mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +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:
@@ -1,5 +1,11 @@
|
||||
#!/bin/bash
|
||||
# Redis startup wrapper for unified container
|
||||
# Smart supervisor: detects external Redis and sleeps instead of starting local instance
|
||||
#
|
||||
# Behavior:
|
||||
# - If REDIS_URL points to external host (not 127.0.0.1/localhost), sleep infinity
|
||||
# - Otherwise, start local Redis instance
|
||||
#
|
||||
# Uses gosu to ensure correct PUID:PGID for file operations
|
||||
#
|
||||
# Supports:
|
||||
@@ -15,11 +21,30 @@ if [ -f /etc/environment ]; then
|
||||
set +a
|
||||
fi
|
||||
|
||||
echo "[Redis] Checking for external Redis configuration..."
|
||||
|
||||
# Extract host from REDIS_URL
|
||||
# Format: redis://host:port or redis://:password@host:port
|
||||
if [ -n "$REDIS_URL" ]; then
|
||||
# Extract the host part (between :// or @, and :port or end)
|
||||
REDIS_HOST=$(echo "$REDIS_URL" | sed -n 's|redis://\([^:@]*@\)\?\([^:/]*\).*|\2|p')
|
||||
|
||||
echo "[Redis] Detected REDIS_URL host: $REDIS_HOST"
|
||||
|
||||
# Check if host is external (not localhost or 127.0.0.1)
|
||||
if [ "$REDIS_HOST" != "127.0.0.1" ] && [ "$REDIS_HOST" != "localhost" ]; then
|
||||
echo "[Redis] ✅ External Redis detected at $REDIS_HOST"
|
||||
echo "[Redis] Skipping local Redis startup - sleeping to keep supervisord happy"
|
||||
exec sleep infinity
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "[Redis] Starting local Redis server..."
|
||||
|
||||
# Get PUID/PGID (default to redis user's current IDs if not set)
|
||||
PUID=${PUID:-$(id -u redis)}
|
||||
PGID=${PGID:-$(id -g redis)}
|
||||
|
||||
echo "[Redis] Starting Redis server..."
|
||||
echo "[Redis] Process will run as UID:GID = $PUID:$PGID"
|
||||
|
||||
# =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user