From a1ca18b7804883a92588de4e6bc8a6e2292d59c4 Mon Sep 17 00:00:00 2001 From: Sameer Naik Date: Sat, 28 Nov 2015 21:06:51 +0530 Subject: [PATCH] `recovery.conf` can exist only on a slave node It's existence otherwise cause issues while replication users, as such the `configure_recovery` function is promoted higher in the initialization sequence. --- entrypoint.sh | 2 +- runtime/functions | 41 ++++++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 79a97d2..9bda3fc 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -21,13 +21,13 @@ if [[ -z ${1} ]]; then create_rundir initialize_database + configure_recovery configure_ssl trust_localnet create_user create_database create_replication_user - configure_recovery echo "Starting PostgreSQL ${PG_VERSION}..." exec start-stop-daemon --start --chuid ${PG_USER}:${PG_USER} \ diff --git a/runtime/functions b/runtime/functions index 41d9177..9e647d3 100755 --- a/runtime/functions +++ b/runtime/functions @@ -252,6 +252,28 @@ trust_localnet() { fi } +configure_recovery() { + if [[ ${REPLICATION_MODE} == slave ]]; then + if [[ ! -f ${PG_RECOVERY_CONF} ]]; then + # initialize recovery.conf on the firstrun (slave only) + echo "Configuring recovery..." + exec_as_postgres touch ${PG_RECOVERY_CONF} + ( echo "standby_mode = 'on'"; + echo "primary_conninfo = 'host=${REPLICATION_HOST} port=${REPLICATION_PORT} user=${REPLICATION_USER} password=${REPLICATION_PASS} sslmode=${REPLICATION_SSLMODE}'"; + echo "trigger_file = '/tmp/postgresql.trigger'" ) > ${PG_RECOVERY_CONF} + else + set_recovery_param "host" "${REPLICATION_HOST}" + set_recovery_param "port" "${REPLICATION_PORT}" + set_recovery_param "user" "${REPLICATION_USER}" + set_recovery_param "password" "${REPLICATION_PASS}" + set_recovery_param "sslmode" "${REPLICATION_SSLMODE}" + fi + else + # recovery.conf can only exist on a slave node, its existence otherwise causes problems + rm -rf ${PG_RECOVERY_CONF} + fi +} + create_user() { if [[ -n ${DB_USER} ]]; then case $REPLICATION_MODE in @@ -319,22 +341,3 @@ create_replication_user() { esac fi } - -configure_recovery() { - if [[ ! -f ${PG_RECOVERY_CONF} ]]; then - if [[ ${REPLICATION_MODE} == slave ]]; then - # initialize recovery.conf on the firstrun (slave only) - echo "Configuring recovery..." - exec_as_postgres touch ${PG_RECOVERY_CONF} - ( echo "standby_mode = 'on'"; - echo "primary_conninfo = 'host=${REPLICATION_HOST} port=${REPLICATION_PORT} user=${REPLICATION_USER} password=${REPLICATION_PASS} sslmode=${REPLICATION_SSLMODE}'"; - echo "trigger_file = '/tmp/postgresql.trigger'" ) > ${PG_RECOVERY_CONF} - fi - else - set_recovery_param "host" "${REPLICATION_HOST}" - set_recovery_param "port" "${REPLICATION_PORT}" - set_recovery_param "user" "${REPLICATION_USER}" - set_recovery_param "password" "${REPLICATION_PASS}" - set_recovery_param "sslmode" "${REPLICATION_SSLMODE}" - fi -}