Skip to content

Commit b32773a

Browse files
committed
Add missing run-postgresql* scripts
1 parent b5af649 commit b32773a

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

Diff for: run-postgresql-master.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
source ${HOME}/common.sh
6+
7+
check_env_vars
8+
generate_passwd_file
9+
generate_postgresql_config
10+
11+
if [ ! -f "$PGDATA/postgresql.conf" ]; then
12+
initialize_database
13+
fi
14+
15+
set_passwords
16+
17+
unset_env_vars
18+
exec postgres "$@"

Diff for: run-postgresql-slave.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
source ${HOME}/common.sh
6+
7+
function initialize_replica() {
8+
echo "Initializing PostgreSQL slave ..."
9+
chmod 0700 $PGDATA
10+
export MASTER_FQDN=$(postgresql_master_addr)
11+
PGPASSWORD="${POSTGRESQL_MASTER_PASSWORD}" pg_basebackup -x --no-password --pgdata ${PGDATA} --host=${MASTER_FQDN} --port=5432 -U "${POSTGRESQL_MASTER_USER}"
12+
13+
# PostgreSQL recovery configuration.
14+
envsubst < ${POSTGRESQL_RECOVERY_FILE}.template > ${POSTGRESQL_RECOVERY_FILE}
15+
cat >> "$PGDATA/recovery.conf" <<EOF
16+
# Custom OpenShift recovery configuration:
17+
include '${POSTGRESQL_RECOVERY_FILE}'
18+
EOF
19+
}
20+
21+
check_env_vars
22+
generate_passwd_file
23+
generate_postgresql_config
24+
25+
initialize_replica
26+
27+
unset_env_vars
28+
exec postgres "$@"

Diff for: run-postgresql.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
# Data dir
6+
if [ -O $HOME/data ]; then
7+
export PGDATA=$HOME/data
8+
else
9+
# If current user does not own data directory
10+
# create a subdirectory that the user does own
11+
if [ ! -d $HOME/data/userdata ]; then
12+
mkdir $HOME/data/userdata
13+
fi
14+
export PGDATA=$HOME/data/userdata
15+
fi
16+
17+
case "${1:-}" in
18+
'postgres-slave' )
19+
set -- run-postgresql-slave.sh "${@:2}"
20+
;;
21+
'postgres' | 'postgres-master' )
22+
set -- run-postgresql-master.sh "${@:2}"
23+
;;
24+
esac
25+
26+
exec "$@"

0 commit comments

Comments
 (0)