-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatastore-entrypoint.sh
60 lines (44 loc) · 1.5 KB
/
datastore-entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
source /usr/local/bin/docker-entrypoint.sh
docker_setup_env
docker_create_db_directories
if [ "$(id -u)" = '0' ]; then
# then restart script as postgres user
exec gosu postgres "$BASH_SOURCE" "$@"
fi
if [ ! -s "$PGDATA/PG_VERSION" ]; then
echo "The postgresql data directory $PGDATA does not exist."
if [ -n "${RUN_AS_REPLICA}" ]; then
echo " Container identifies a secondary instance hence starting from base backup"
export PGPASSWORD=${REPLICATION_PASSWORD}
pg_basebackup -h "${REPLICATION_HOST}" -U replicator -p 5432 -D "${PGDATA}" -S "${REPLICATION_SLOT}" -Fp -Xs -R
unset PGPASSWORD
if [ $? -ne 0 ]; then
echo " Failed to execute pg_basebackup."
exit 1
fi
else
echo " Container identifies as the primary hence starting it normally"
if [ $PERFORM_RECOVERY = "TRUE" ]; then
echo " Instance starting from a backup as configured"
# Restore base backup.
# Will create a new Database Cluster.
wal-g backup-fetch "$PGDATA" LATEST
# Move recovery.conf to cluster to tell postgres where to fetch WAL from.
mv /etc/recovery.conf $PGDATA
chown -R postgres:postgres $PGDATA
chmod 700 $PGDATA
else
docker_init_database_dir
pg_setup_hba_conf "$@"
export PGPASSWORD=${POSTGRES_PASSWORD}
docker_temp_server_start "$@"
docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/*
docker_temp_server_stop
unset PGPASSWORD
fi
fi
echo;
fi
exec "$@"