-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e12bd3
commit e29b1ee
Showing
2 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env bash | ||
set -Eeo pipefail | ||
shopt -s extglob | ||
|
||
CURRENT_PGVERSION="" | ||
EXPECTED_PGVERSION="$PG_MAJOR" | ||
if [[ -f "/var/lib/postgresql/data/PG_VERSION" ]]; then | ||
CURRENT_PGVERSION="$(cat /var/lib/postgresql/data/PG_VERSION)" | ||
fi | ||
|
||
if [[ "$CURRENT_PGVERSION" != "$EXPECTED_PGVERSION" ]] && \ | ||
[[ "$CURRENT_PGVERSION" != "" ]]; then | ||
sed -i "s/$/ $CURRENT_PGVERSION/" /etc/apt/sources.list.d/pgdg.list | ||
apt-get update && apt-get install -y --no-install-recommends \ | ||
postgresql-$CURRENT_PGVERSION \ | ||
postgresql-contrib-$CURRENT_PGVERSION \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
export PGBINOLD="/usr/lib/postgresql/$CURRENT_PGVERSION/bin" | ||
export PGDATABASE="/var/lib/postgresql/data" | ||
export PGDATAOLD="/var/lib/postgresql/data/$CURRENT_PGVERSION" | ||
export PGDATANEW="/var/lib/postgresql/data/$EXPECTED_PGVERSION" | ||
|
||
mkdir -p "$PGDATANEW" "$PGDATAOLD" | ||
find "$PGDATABASE" -maxdepth 1 -mindepth 1 \ | ||
-not -wholename "$PGDATAOLD" \ | ||
-not -wholename "$PGDATANEW" \ | ||
-exec mv {} "$PGDATAOLD/" \; | ||
|
||
chmod 700 "$PGDATAOLD" "$PGDATANEW" | ||
chown postgres . | ||
chown -R postgres "$PGDATAOLD" "$PGDATANEW" "$PGDATABASE" | ||
if [ ! -s "$PGDATANEW/PG_VERSION" ]; then | ||
PGDATA="$PGDATANEW" eval "gosu postgres initdb $POSTGRES_INITDB_ARGS" | ||
fi | ||
|
||
gosu postgres pg_upgrade | ||
rm $PGDATANEW/*.conf | ||
mv $PGDATANEW/* "$PGDATABASE" | ||
mv $PGDATAOLD/*.conf "$PGDATABASE" | ||
rm -r "$PGDATANEW" | ||
./delete_old_cluster.sh | ||
rm ./analyze_new_cluster.sh | ||
fi | ||
|
||
exec ./entrypoint.sh "$@" |