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.
This commit is contained in:
Sameer Naik
2015-11-28 21:06:51 +05:30
parent 22c969c88c
commit a1ca18b780
2 changed files with 23 additions and 20 deletions
+1 -1
View File
@@ -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} \
+22 -19
View File
@@ -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
}