2026-02-23 14:14:06 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
set -Eeo pipefail
|
|
|
|
|
|
2026-02-27 10:48:28 +01:00
|
|
|
file_env() {
|
|
|
|
|
local var="$1"
|
|
|
|
|
local fileVar="${var}_FILE"
|
|
|
|
|
local def="${2:-}"
|
|
|
|
|
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
|
|
|
|
|
printf >&2 'error: both %s and %s are set (but are exclusive)\n' "$var" "$fileVar"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
local val="$def"
|
|
|
|
|
if [ "${!var:-}" ]; then
|
|
|
|
|
val="${!var}"
|
|
|
|
|
elif [ "${!fileVar:-}" ]; then
|
|
|
|
|
val="$(< "${!fileVar}")"
|
|
|
|
|
fi
|
|
|
|
|
export "$var"="$val"
|
|
|
|
|
unset "$fileVar"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
docker_setup_env() {
|
|
|
|
|
file_env 'PGPOOL_ADMIN_USERNAME'
|
|
|
|
|
file_env 'PGPOOL_ADMIN_PASSWORD'
|
|
|
|
|
file_env 'POSTGRES_PGPOOL_USERNAME'
|
|
|
|
|
file_env 'POSTGRES_PGPOOL_PASSWORD'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if [ "$(id -u)" = '0' ]; then
|
|
|
|
|
exec gosu postgres "$BASH_SOURCE"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
install --directory --owner postgres --group postgres --mode 700 /var/lib/postgresql/.ssh
|
|
|
|
|
cp /ssh/* /var/lib/postgresql/.ssh/
|
|
|
|
|
chmod 600 /var/lib/postgresql/.ssh/*
|
|
|
|
|
|
|
|
|
|
docker_setup_env
|
2026-02-23 14:14:06 +01:00
|
|
|
|
2026-02-27 11:12:20 +01:00
|
|
|
printf "%s:%s\n" "$PGPOOL_ADMIN_USERNAME" "(pg_md5 "$PGPOOL_ADMIN_PASSWORD)" > /etc/pgpool2/pcp.conf
|
2026-02-24 10:48:49 +01:00
|
|
|
{
|
2026-02-27 10:48:28 +01:00
|
|
|
printf "localhost:9898:%s:%s\n" "$PGPOOL_ADMIN_USERNAME" "$PGPOOL_ADMIN_PASSWORD"
|
|
|
|
|
printf "pgpool:9898:%s:%s\n" "$PGPOOL_ADMIN_USERNAME" "$PGPOOL_ADMIN_PASSWORD"
|
|
|
|
|
} > ~/.pcppass
|
|
|
|
|
chmod 600 /etc/pgpool2/pcp.conf ~/.pcppass
|
2026-02-24 10:48:49 +01:00
|
|
|
|
2026-02-27 10:48:28 +01:00
|
|
|
|
2026-02-27 11:08:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
printf "listen_addresses = '*'\n"
|
|
|
|
|
printf "port = 5432\n"
|
|
|
|
|
printf "unix_socket_directories = '/run'\n"
|
|
|
|
|
printf "pcp_socket_dir = '/run'\n"
|
|
|
|
|
printf "enable_pool_hba = off\n"
|
|
|
|
|
printf "allow_clear_text_frontend_auth = on\n"
|
|
|
|
|
printf "process_management_mode = 'dynamic'\n"
|
|
|
|
|
printf "backend_clustering_mode = 'raw'\n"
|
|
|
|
|
printf "health_check_timeout = 5\n"
|
|
|
|
|
printf "health_check_period = 5\n"
|
|
|
|
|
printf "health_check_user = 'pgpool'\n"
|
|
|
|
|
printf "health_check_password = '%s'\n" "$PGPOOL_PASSWORD"
|
|
|
|
|
|
|
|
|
|
IFS=':'
|
|
|
|
|
n=0
|
|
|
|
|
for backend in $PGPOOL_BACKEND
|
|
|
|
|
do
|
|
|
|
|
printf "backend_hostname%d = '%s'\n" $n $backend
|
|
|
|
|
printf "backend_port%d = 5432\n" $n
|
|
|
|
|
((n+=1))
|
|
|
|
|
done
|
|
|
|
|
} > /etc/pgpool2/pgpool.conf
|
2026-02-27 10:48:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
sudo service ssh start
|
2026-02-24 11:28:26 +01:00
|
|
|
sudo /usr/sbin/pgpool
|
2026-02-23 15:59:17 +01:00
|
|
|
|
2026-02-23 14:14:06 +01:00
|
|
|
while true
|
|
|
|
|
do
|
|
|
|
|
echo "$(date)"
|
|
|
|
|
sleep 3600
|
|
|
|
|
done
|