freshyo-deploy/replicator-side/replica-entrypoint.sh
2026-01-25 16:19:31 +00:00

34 lines
696 B
Bash
Executable file

#!/bin/bash
set -e
DATA_DIR="/var/lib/postgresql/data"
if [ ! -f "$DATA_DIR/PG_VERSION" ]; then
echo "Running pg_basebackup from primary..."
rm -rf "$DATA_DIR"/*
export PGPASSWORD="$REPLICATION_PASSWORD"
pg_basebackup \
-h "$PRIMARY_HOST" \
-p "$PRIMARY_PORT" \
-U "$REPLICATION_USER" \
-D "$DATA_DIR" \
-Fp \
-Xs \
-R \
-P
echo "Fixing ownership and permissions..."
chown -R postgres:postgres "$DATA_DIR"
chmod 0700 "$DATA_DIR"
else
echo "Replica already initialized"
fi
echo "Starting postgres as postgres user..."
exec gosu postgres postgres \
-c config_file=/etc/postgresql/postgresql.conf \
-c hba_file=/etc/postgresql/pg_hba.conf