cleanup and start ssh
This commit is contained in:
@@ -1,88 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
source /usr/local/bin/docker-entrypoint.sh
|
|
||||||
|
|
||||||
server_start() {
|
|
||||||
NOTIFY_SOCKET= \
|
|
||||||
PGUSER="${PGUSER:-$POSTGRES_USER}" \
|
|
||||||
pg_ctl -D "$PGDATA" \
|
|
||||||
-o "-c listen_addresses='*' -p ${PGPORT:-5432}" \
|
|
||||||
-w start
|
|
||||||
}
|
|
||||||
|
|
||||||
create_repmgr() {
|
|
||||||
psql -c "CREATE USER repmgr WITH SUPERUSER ENCRYPTED PASSWORD '${REPMGR_PASSWORD}';"
|
|
||||||
psql -c "CREATE DATABASE repmgr WITH OWNER repmgr;"
|
|
||||||
psql -c 'ALTER USER repmgr SET search_path TO repmgr, "$user", public;'
|
|
||||||
}
|
|
||||||
|
|
||||||
create_hba() {
|
|
||||||
echo "local all all trust" > /var/lib/postgresql/data/pg_hba.conf
|
|
||||||
echo "local replication repmgr trust" >> /var/lib/postgresql/data/pg_hba.conf
|
|
||||||
echo "host replication repmgr 127.0.0.1/32 trust" >> /var/lib/postgresql/data/pg_hba.conf
|
|
||||||
echo "host replication repmgr ${POSTGRES_NETWORK:-100.64.0.0/10} trust" >> /var/lib/postgresql/data/pg_hba.conf
|
|
||||||
echo "local repmgr repmgr trust" >> /var/lib/postgresql/data/pg_hba.conf
|
|
||||||
echo "host repmgr repmgr 127.0.0.1/32 trust" >> /var/lib/postgresql/data/pg_hba.conf
|
|
||||||
echo "host repmgr repmgr ${POSTGRES_NETWORK:-100.64.0.0/10} trust" >> /var/lib/postgresql/data/pg_hba.conf
|
|
||||||
echo "host all all all scram-sha-256" >> /var/lib/postgresql/data/pg_hba.conf
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "node_id = ${REPMGR_NODE_ID}" > /etc/repmgr/repmgr.conf
|
|
||||||
echo "node_name = ${REPMGR_NODE_NAME}" >> /etc/repmgr/repmgr.conf
|
|
||||||
echo "conninfo = 'host=${REPMGR_NODE_NAME} dbname=repmgr user=repmgr connect_timeout=2'" >> /etc/repmgr/repmgr.conf
|
|
||||||
echo "location = '${REPMGR_NODE_LOCATION}'" >> /etc/repmgr/repmgr.conf
|
|
||||||
echo "data_directory = '/var/lib/postgresql/data'" >> /etc/repmgr/repmgr.conf
|
|
||||||
echo "use_replication_slots = on" >> /etc/repmgr/repmgr.conf
|
|
||||||
echo "pg_bindir = '/usr/lib/postgresql/15/bin/'" >> /etc/repmgr/repmgr.conf
|
|
||||||
echo "failover = automatic" >> /etc/repmgr/repmgr.conf
|
|
||||||
echo "promote_command = '/usr/bin/repmgr standby promote -f /etc/repmgr.conf --log-to-file'" >> /etc/repmgr/repmgr.conf
|
|
||||||
echo "follow_command = '/usr/bin/repmgr standby follow -f /etc/repmgr.conf --log-to-file --upstream-node-id=%n'" >> /etc/repmgr/repmgr.conf
|
|
||||||
echo "primary_visibility_consensus = on" >> /etc/repmgr/repmgr.conf
|
|
||||||
|
|
||||||
|
|
||||||
if [[ -n $REPMGR_UPSTREAM ]] && [[ -z $REPMGR_NODE_ROLE ]]; then
|
|
||||||
REPMGR_NODE_ROLE="standby"
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$REPMGR_NODE_ROLE" in
|
|
||||||
standby )
|
|
||||||
docker_temp_server_stop
|
|
||||||
rm -rf /var/lib/postgresql/data/*
|
|
||||||
until /usr/lib/postgresql/15/bin/repmgr -h $REPMGR_UPSTREAM -U repmgr -f /etc/repmgr/repmgr.conf standby clone --dry-run &> /dev/null
|
|
||||||
do
|
|
||||||
echo "Upstream host not ready. Waiting for 5 minutes..."
|
|
||||||
sleep 300
|
|
||||||
done
|
|
||||||
echo "Upstream host found..."
|
|
||||||
/usr/lib/postgresql/15/bin/repmgr -h $REPMGR_UPSTREAM -U repmgr -f /etc/repmgr/repmgr.conf standby clone
|
|
||||||
server_start
|
|
||||||
/usr/lib/postgresql/15/bin/repmgr -f /etc/repmgr/repmgr.conf standby register
|
|
||||||
;;
|
|
||||||
witness )
|
|
||||||
create_repmgr
|
|
||||||
docker_temp_server_stop
|
|
||||||
create_hba
|
|
||||||
server_start
|
|
||||||
until /usr/lib/postgresql/15/bin/repmgr -h $REPMGR_UPSTREAM -f /etc/repmgr/repmgr.conf witness register &> /dev/null
|
|
||||||
do
|
|
||||||
echo "Primary host not ready. Waiting for 5 minutes..."
|
|
||||||
sleep 300
|
|
||||||
done
|
|
||||||
;;
|
|
||||||
* )
|
|
||||||
create_repmgr
|
|
||||||
docker_temp_server_stop
|
|
||||||
echo "archive_command = '/bin/true'" >> /var/lib/postgresql/data/postgresql.conf
|
|
||||||
echo "archive_mode = on" >> /var/lib/postgresql/data/postgresql.conf
|
|
||||||
echo "hot_standby = on" >> /var/lib/postgresql/data/postgresql.conf
|
|
||||||
echo "max_wal_senders = 10" >> /var/lib/postgresql/data/postgresql.conf
|
|
||||||
echo "max_replication_slots = 10" >> /var/lib/postgresql/data/postgresql.conf
|
|
||||||
echo "shared_preload_libraries = 'repmgr'" >> /var/lib/postgresql/data/postgresql.conf
|
|
||||||
if [[ -n $POSTGRES_MAX_CONNECTIONS ]]; then
|
|
||||||
echo "max_connections = ${POSTGRES_MAX_CONNECTIONS}" >> /var/lib/postgresql/data/postgresql.conf
|
|
||||||
fi
|
|
||||||
create_hba
|
|
||||||
server_start
|
|
||||||
/usr/lib/postgresql/15/bin/repmgr -f /etc/repmgr/repmgr.conf primary register
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
@@ -184,6 +184,8 @@ if [[ ! -s "$PGDATA/PG_VERSION" ]]; then
|
|||||||
docker_temp_server_stop
|
docker_temp_server_stop
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
service ssh start
|
||||||
|
|
||||||
set -m
|
set -m
|
||||||
|
|
||||||
postgres &
|
postgres &
|
||||||
|
|||||||
Reference in New Issue
Block a user