docker-entrypoint.shā¢1.99 kB
#!/bin/bash
# Docker entrypoint for MCP Server with embedded PgBouncer
set -e
echo "š Starting YT PostgreSQL MCP Server..."
# Check if PgBouncer is enabled
if [ "${PGBOUNCER_ENABLED}" = "true" ]; then
echo "š¦ PgBouncer enabled - preparing configuration..."
# Check required environment variables
if [ -z "$POSTGRES_USER" ] || [ -z "$POSTGRES_PASSWORD" ]; then
echo "ā ļø Warning: POSTGRES_USER or POSTGRES_PASSWORD not set"
echo " PgBouncer will be configured, but may fail to connect"
fi
# Get real PostgreSQL host/port (what PgBouncer connects to)
REAL_HOST="${POSTGRES_REAL_HOST:-${POSTGRES_HOST:-localhost}}"
REAL_PORT="${POSTGRES_REAL_PORT:-${POSTGRES_PORT:-5432}}"
# Update pgbouncer.ini with real PostgreSQL connection
sed -i "s/\${POSTGRES_HOST}/${REAL_HOST}/g" /etc/pgbouncer/pgbouncer.ini
sed -i "s/\${POSTGRES_PORT}/${REAL_PORT}/g" /etc/pgbouncer/pgbouncer.ini
sed -i "s/\${POSTGRES_DATABASE}/${POSTGRES_DATABASE:-postgres}/g" /etc/pgbouncer/pgbouncer.ini
# Generate userlist.txt with plain password
echo "\"$POSTGRES_USER\" \"$POSTGRES_PASSWORD\"" > /etc/pgbouncer/userlist.txt
chmod 600 /etc/pgbouncer/userlist.txt
echo "ā
PgBouncer configuration complete"
echo " Connecting to PostgreSQL at ${REAL_HOST}:${REAL_PORT}/${POSTGRES_DATABASE}"
echo " Listening on localhost:6432"
# Start PgBouncer in background
echo "š Starting PgBouncer..."
pgbouncer -d /etc/pgbouncer/pgbouncer.ini
# Wait a moment for PgBouncer to start
sleep 2
# Check if PgBouncer is running
if pgrep -x "pgbouncer" > /dev/null; then
echo "ā
PgBouncer started successfully (PID: $(pgrep -x pgbouncer))"
else
echo "ā PgBouncer failed to start"
exit 1
fi
else
echo "š¦ PgBouncer disabled - connecting directly to PostgreSQL"
fi
# Start MCP Server
echo "š Starting MCP Server..."
exec python -m src.yt_postgres_mcp.server