avoid duplicate entries in configuration files. Refer #40

This commit is contained in:
Sameer Naik
2015-11-23 20:46:11 +05:30
parent b4a5810e13
commit f3b18c1f1b
+26 -33
View File
@@ -77,15 +77,11 @@ if [[ ! -d ${PG_DATADIR} ]]; then
PGPASSWORD=$REPLICATION_PASS ${PG_BINDIR}/pg_basebackup -D ${PG_DATADIR} \ PGPASSWORD=$REPLICATION_PASS ${PG_BINDIR}/pg_basebackup -D ${PG_DATADIR} \
-h ${REPLICATION_HOST} -p ${REPLICATION_PORT} -U ${REPLICATION_USER} -X stream -w -v -P -h ${REPLICATION_HOST} -p ${REPLICATION_PORT} -U ${REPLICATION_USER} -X stream -w -v -P
echo "Setting up hot standby configuration..." echo "Setting up hot standby configuration..."
cat >> ${PG_CONFDIR}/postgresql.conf <<EOF sudo -Hu ${PG_USER} sed -i "s|^#hot_standby = .*|hot_standby = on|" ${PG_CONFDIR}/postgresql.conf
hot_standby = on
EOF
sudo -Hu ${PG_USER} touch ${PG_DATADIR}/recovery.conf sudo -Hu ${PG_USER} touch ${PG_DATADIR}/recovery.conf
cat >> ${PG_DATADIR}/recovery.conf <<EOF ( echo "standby_mode = 'on'";
standby_mode = 'on' echo "primary_conninfo = 'host=${REPLICATION_HOST} port=${REPLICATION_PORT} user=${REPLICATION_USER} password=${REPLICATION_PASS} sslmode=${PSQL_SSLMODE}'";
primary_conninfo = 'host=${REPLICATION_HOST} port=${REPLICATION_PORT} user=${REPLICATION_USER} password=${REPLICATION_PASS} sslmode=${PSQL_SSLMODE}' echo "trigger_file = '/tmp/postgresql.trigger'" ) > ${PG_DATADIR}/recovery.conf
trigger_file = '/tmp/postgresql.trigger'
EOF
fi fi
else else
@@ -129,54 +125,51 @@ if [[ -n ${PG_OLD_VERSION} ]]; then
fi fi
if [[ ${PSQL_SSLMODE} == disable ]]; then if [[ ${PSQL_SSLMODE} == disable ]]; then
sed 's/ssl = true/#ssl = true/' -i ${PG_CONFDIR}/postgresql.conf sudo -Hu ${PG_USER} sed -i "s|^[#]*[ ]*ssl = .*|ssl = false|" ${PG_CONFDIR}/postgresql.conf
else
sudo -Hu ${PG_USER} sed -i "s|^[#]*[ ]*ssl = .*|ssl = true|" ${PG_CONFDIR}/postgresql.conf
fi fi
# Change DSM from `posix' to `sysv' if we are inside an lx-brand container # Change DSM from `posix' to `sysv' if we are inside an lx-brand container
if [[ $(uname -v) == "BrandZ virtual linux" ]]; then if [[ $(uname -v) == "BrandZ virtual linux" ]]; then
sed 's/\(dynamic_shared_memory_type = \)posix/\1sysv/' \ sed 's/\(dynamic_shared_memory_type = \)posix/\1sysv/' -i ${PG_CONFDIR}/postgresql.conf
-i ${PG_CONFDIR}/postgresql.conf
fi fi
# listen on all interfaces # listen on all interfaces
cat >> ${PG_CONFDIR}/postgresql.conf <<EOF sudo -Hu ${PG_USER} sed -i "s|^[#]*[ ]*listen_addresses = .*|listen_addresses = '*'|" ${PG_CONFDIR}/postgresql.conf
listen_addresses = '*'
EOF
if [[ ${PSQL_TRUST_LOCALNET} == true ]]; then if [[ ${PSQL_TRUST_LOCALNET} == true ]]; then
echo "Enabling trust samenet in pg_hba.conf..." if ! grep -q "host \+all \+all \+samenet \+trust" ${PG_CONFDIR}/pg_hba.conf; then
cat >> ${PG_CONFDIR}/pg_hba.conf <<EOF echo "Enabling trust samenet in pg_hba.conf..."
host all all samenet trust echo "host all all samenet trust" >> ${PG_CONFDIR}/pg_hba.conf
EOF fi
fi fi
# allow remote connections to postgresql database # allow remote connections to postgresql database
cat >> ${PG_CONFDIR}/pg_hba.conf <<EOF if ! grep -q "host \+all \+all \+0.0.0.0/0 \+md5" ${PG_CONFDIR}/pg_hba.conf; then
host all all 0.0.0.0/0 md5 echo "host all all 0.0.0.0/0 md5" >> ${PG_CONFDIR}/pg_hba.conf
EOF fi
# allow replication connections to the database # allow replication connections to the database
if [[ -n ${REPLICATION_USER} ]]; then if [[ -n ${REPLICATION_USER} ]]; then
if [[ ${PSQL_SSLMODE} == disable ]]; then if [[ ${PSQL_SSLMODE} == disable ]]; then
cat >> ${PG_CONFDIR}/pg_hba.conf <<EOF if ! grep -q "host \+replication \+$REPLICATION_USER \+0.0.0.0/0 \+md5" ${PG_CONFDIR}/pg_hba.conf; then
host replication $REPLICATION_USER 0.0.0.0/0 md5 echo "host replication $REPLICATION_USER 0.0.0.0/0 md5" >> ${PG_CONFDIR}/pg_hba.conf
EOF fi
else else
cat >> ${PG_CONFDIR}/pg_hba.conf <<EOF if ! grep -q "hostssl \+replication \+$REPLICATION_USER \+0.0.0.0/0 \+md5" ${PG_CONFDIR}/pg_hba.conf; then
hostssl replication $REPLICATION_USER 0.0.0.0/0 md5 echo "hostssl replication $REPLICATION_USER 0.0.0.0/0 md5" >> ${PG_CONFDIR}/pg_hba.conf
EOF fi
fi fi
fi fi
if [[ ${PSQL_MODE} == master ]]; then if [[ ${PSQL_MODE} == master ]]; then
if [[ -n ${REPLICATION_USER} ]]; then if [[ -n ${REPLICATION_USER} ]]; then
echo "Supporting hot standby..." echo "Supporting hot standby..."
cat >> ${PG_CONFDIR}/postgresql.conf <<EOF sudo -Hu ${PG_USER} sed -i "s|^#wal_level = .*|wal_level = hot_standby|" ${PG_CONFDIR}/postgresql.conf
wal_level = hot_standby sudo -Hu ${PG_USER} sed -i "s|^#max_wal_senders = .*|max_wal_senders = 3|" ${PG_CONFDIR}/postgresql.conf
max_wal_senders = 3 sudo -Hu ${PG_USER} sed -i "s|^#checkpoint_segments = .*|checkpoint_segments = 8|" ${PG_CONFDIR}/postgresql.conf
checkpoint_segments = 8 sudo -Hu ${PG_USER} sed -i "s|^#wal_keep_segments = .*|wal_keep_segments = 8|" ${PG_CONFDIR}/postgresql.conf
wal_keep_segments = 8
EOF
fi fi
fi fi