Skip to main content
Glama
yty-build
by yty-build
entrypoint.sh1.96 kB
#!/bin/bash set -e # Function to generate MD5 password hash for PgBouncer generate_md5_hash() { local username="$1" local password="$2" echo -n "md5$(echo -n "${password}${username}" | md5sum | cut -d' ' -f1)" } # Check required environment variables if [ -z "$POSTGRES_USER" ] || [ -z "$POSTGRES_PASSWORD" ] || \ [ -z "$POSTGRES_HOST" ] || [ -z "$POSTGRES_DATABASE" ]; then echo "ERROR: Required environment variables not set:" echo " - POSTGRES_USER: ${POSTGRES_USER:-<not set>}" echo " - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:+<set>}" echo " - POSTGRES_HOST: ${POSTGRES_HOST:-<not set>}" echo " - POSTGRES_DATABASE: ${POSTGRES_DATABASE:-<not set>}" exit 1 fi # Generate userlist.txt with plain password for auth_type=plain echo "Generating PgBouncer userlist.txt..." # For auth_type=plain, store password in plaintext (PgBouncer will handle encryption to PostgreSQL) echo "\"$POSTGRES_USER\" \"$POSTGRES_PASSWORD\"" > /etc/pgbouncer/userlist.txt # Update pgbouncer.ini with environment variables echo "Configuring PgBouncer..." sed -i "s/\${POSTGRES_HOST}/${POSTGRES_HOST}/g" /etc/pgbouncer/pgbouncer.ini sed -i "s/\${POSTGRES_PORT}/${POSTGRES_PORT:-5432}/g" /etc/pgbouncer/pgbouncer.ini sed -i "s/\${POSTGRES_DATABASE}/${POSTGRES_DATABASE}/g" /etc/pgbouncer/pgbouncer.ini # Update admin_users to include actual database user for health checks sed -i "s/admin_users = postgres/admin_users = postgres, ${POSTGRES_USER}/g" /etc/pgbouncer/pgbouncer.ini sed -i "s/stats_users = postgres/stats_users = postgres, ${POSTGRES_USER}/g" /etc/pgbouncer/pgbouncer.ini # Set proper permissions chmod 600 /etc/pgbouncer/userlist.txt chmod 644 /etc/pgbouncer/pgbouncer.ini echo "PgBouncer configuration complete" echo "Connecting to PostgreSQL at ${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}" echo "Starting PgBouncer..." # Start PgBouncer in foreground exec pgbouncer -u pgbouncer /etc/pgbouncer/pgbouncer.ini

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yty-build/postgres_mcp_allaccess'

If you have feedback or need assistance with the MCP directory API, please join our Discord server