Skip to content

Commit 6fa669d

Browse files
authored
Merge pull request #477 from vpodzime/master-pg_hba_upgrade
ENT-4231: Preserve the 'pg_hba.conf' file on upgrades
2 parents b43df80 + 7c4b756 commit 6fa669d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packaging/common/cfengine-hub/postinstall.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ if [ ! -d $PREFIX/state/pg/data ]; then
399399
cp -a "$new_pgconfig_file" $PREFIX/state/pg/data/postgresql.conf
400400
chown cfpostgres $PREFIX/state/pg/data/postgresql.conf
401401
else
402+
# Always use the original pg_hba.conf file, it defines access control to PostgreSQL
403+
cp -a "$BACKUP_DIR/data/pg_hba.conf" "$PREFIX/state/pg/data/pg_hba.conf"
404+
chown cfpostgres "$PREFIX/state/pg/data/pg_hba.conf"
405+
402406
# Determine which postgresql.conf file to use and put it in the right place.
403407
if [ -f "$BACKUP_DIR/data/postgresql.conf.modified" ]; then
404408
# User-modified file from the previous old version of CFEngine exists, try to use it.
@@ -427,6 +431,14 @@ if [ ! -d $PREFIX/state/pg/data ]; then
427431
cp -a "$new_pgconfig_file" "$PREFIX/state/pg/data/postgresql.conf"
428432
chown cfpostgres "$PREFIX/state/pg/data/postgresql.conf"
429433
fi
434+
435+
# Preserve the recovery.conf file if it existed, it defines how this
436+
# PostgreSQL should behave as a slave (has to be done AFTER checking/writing
437+
# the postgresql.conf file above).
438+
if [ -f "$BACKUP_DIR/data/recovery.conf" ]; then
439+
cp -a "$BACKUP_DIR/data/recovery.conf" "$PREFIX/state/pg/data/recovery.conf"
440+
chown cfpostgres "$PREFIX/state/pg/data/recovery.conf"
441+
fi
430442
fi
431443
fi
432444

0 commit comments

Comments
 (0)