2018-03-21 20:53:39 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2020-04-14 17:00:36 +00:00
|
|
|
source /scripts/env-data.sh
|
2020-04-08 08:15:45 +00:00
|
|
|
|
2018-03-21 20:53:39 +00:00
|
|
|
# Setup postgres CONF file
|
2019-01-30 19:06:28 +00:00
|
|
|
|
2020-04-14 17:00:36 +00:00
|
|
|
source /scripts/setup-conf.sh
|
2018-03-21 20:53:39 +00:00
|
|
|
|
|
|
|
# Setup ssl
|
2020-04-14 17:00:36 +00:00
|
|
|
source /scripts/setup-ssl.sh
|
2018-03-21 20:53:39 +00:00
|
|
|
|
|
|
|
# Setup pg_hba.conf
|
2019-02-01 11:04:36 +00:00
|
|
|
|
2020-04-14 17:00:36 +00:00
|
|
|
source /scripts/setup-pg_hba.sh
|
2021-06-06 15:36:15 +00:00
|
|
|
# Function to add figlet
|
|
|
|
figlet -t "Kartoza Docker PostGIS"
|
|
|
|
|
2022-04-27 06:30:16 +00:00
|
|
|
|
|
|
|
if [[ -f /scripts/.pass_20.txt ]]; then
|
|
|
|
USER_CREDENTIAL_PASS=$(cat /scripts/.pass_20.txt)
|
|
|
|
cp /scripts/.pass_20.txt /tmp/PGPASSWORD.txt
|
|
|
|
echo -e "[Entrypoint] GENERATED Postgres PASSWORD: \e[1;31m $USER_CREDENTIAL_PASS"
|
|
|
|
echo -e "\033[0m PGPASSWORD Generated above: "
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -f /scripts/.pass_22.txt ]]; then
|
|
|
|
USER_CREDENTIAL_PASS=$(cat /scripts/.pass_22.txt)
|
|
|
|
cp /scripts/.pass_22.txt /tmp/REPLPASSWORD.txt
|
|
|
|
echo -e "[Entrypoint] GENERATED Replication PASSWORD: \e[1;34m $USER_CREDENTIAL_PASS"
|
|
|
|
echo -e "\033[0m Replication password Generated above: "
|
|
|
|
fi
|
|
|
|
|
2018-03-21 20:53:39 +00:00
|
|
|
|
2019-01-30 19:06:28 +00:00
|
|
|
if [[ -z "$REPLICATE_FROM" ]]; then
|
2020-01-26 06:54:13 +00:00
|
|
|
# This means this is a master instance. We check that database exists
|
|
|
|
echo "Setup master database"
|
2020-04-14 17:00:36 +00:00
|
|
|
source /scripts/setup-database.sh
|
2020-01-26 06:54:13 +00:00
|
|
|
entry_point_script
|
|
|
|
kill_postgres
|
2018-03-21 20:53:39 +00:00
|
|
|
else
|
2020-01-26 06:54:13 +00:00
|
|
|
# This means this is a slave/replication instance.
|
|
|
|
echo "Setup slave database"
|
2020-04-14 17:00:36 +00:00
|
|
|
source /scripts/setup-replication.sh
|
2018-03-21 20:53:39 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# If no arguments passed to entrypoint, then run postgres by default
|
2019-01-30 19:06:28 +00:00
|
|
|
if [[ $# -eq 0 ]];
|
2018-03-21 20:53:39 +00:00
|
|
|
then
|
2020-01-26 06:54:13 +00:00
|
|
|
echo "Postgres initialisation process completed .... restarting in foreground"
|
2019-01-25 12:57:23 +00:00
|
|
|
|
2020-01-26 06:54:13 +00:00
|
|
|
su - postgres -c "$SETVARS $POSTGRES -D $DATADIR -c config_file=$CONF"
|
2018-03-21 20:53:39 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If arguments passed, run postgres with these arguments
|
|
|
|
# This will make sure entrypoint will always be executed
|
2019-01-25 12:57:23 +00:00
|
|
|
if [[ "${1:0:1}" = '-' ]]; then
|
2020-01-26 06:54:13 +00:00
|
|
|
# append postgres into the arguments
|
|
|
|
set -- postgres "$@"
|
2018-03-21 20:53:39 +00:00
|
|
|
fi
|
|
|
|
|
2021-06-06 15:36:15 +00:00
|
|
|
|
2018-03-21 20:53:39 +00:00
|
|
|
exec su - "$@"
|