From 3231f4a4d8d298e038b3ca309228713150a70f28 Mon Sep 17 00:00:00 2001 From: Victor Heng Date: Tue, 14 Jul 2015 19:25:53 +0800 Subject: [PATCH 1/2] Check that vol actually contains DB files, as opposed to a non-empty dir. Referencing file list here: http://www.postgresql.org/docs/9.1/static/storage-file-layout.html --- 9.0/docker-entrypoint.sh | 28 +++++++++++++++------------- 9.1/docker-entrypoint.sh | 28 +++++++++++++++------------- 9.2/docker-entrypoint.sh | 28 +++++++++++++++------------- 9.3/docker-entrypoint.sh | 28 +++++++++++++++------------- 9.4/docker-entrypoint.sh | 28 +++++++++++++++------------- 9.5/docker-entrypoint.sh | 28 +++++++++++++++------------- docker-entrypoint.sh | 28 +++++++++++++++------------- 7 files changed, 105 insertions(+), 91 deletions(-) diff --git a/9.0/docker-entrypoint.sh b/9.0/docker-entrypoint.sh index 27c98d2147..40eb716850 100755 --- a/9.0/docker-entrypoint.sh +++ b/9.0/docker-entrypoint.sh @@ -2,17 +2,19 @@ set -e if [ "$1" = 'postgres' ]; then + mkdir -p "$PGDATA" chown -R postgres "$PGDATA" - + chmod g+s /run/postgresql chown -R postgres:postgres /run/postgresql - - if [ -z "$(ls -A "$PGDATA")" ]; then + + # look specifically for PG_VERSION, as it is expected in the DB dir + if [ -z "$(ls -A "$PGDATA"/PG_VERSION)" ]; then gosu postgres initdb - + sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf - - # check password first so we can ouptut the warning before postgres + + # check password first so we can output the warning before postgres # messes it up if [ "$POSTGRES_PASSWORD" ]; then pass="PASSWORD '$POSTGRES_PASSWORD'" @@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then Docker's default configuration, this is effectively any other container on the same system. - + Use "-e POSTGRES_PASSWORD=password" to set it in "docker run". **************************************************** EOWARN - + pass= authMethod=trust fi - + : ${POSTGRES_USER:=postgres} : ${POSTGRES_DB:=$POSTGRES_USER} @@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then EOSQL echo fi - + if [ "$POSTGRES_USER" = 'postgres' ]; then op='ALTER' else @@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; EOSQL echo - + { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf - + if [ -d /docker-entrypoint-initdb.d ]; then for f in /docker-entrypoint-initdb.d/*.sh; do [ -f "$f" ] && . "$f" done fi fi - + exec gosu postgres "$@" fi diff --git a/9.1/docker-entrypoint.sh b/9.1/docker-entrypoint.sh index 27c98d2147..40eb716850 100755 --- a/9.1/docker-entrypoint.sh +++ b/9.1/docker-entrypoint.sh @@ -2,17 +2,19 @@ set -e if [ "$1" = 'postgres' ]; then + mkdir -p "$PGDATA" chown -R postgres "$PGDATA" - + chmod g+s /run/postgresql chown -R postgres:postgres /run/postgresql - - if [ -z "$(ls -A "$PGDATA")" ]; then + + # look specifically for PG_VERSION, as it is expected in the DB dir + if [ -z "$(ls -A "$PGDATA"/PG_VERSION)" ]; then gosu postgres initdb - + sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf - - # check password first so we can ouptut the warning before postgres + + # check password first so we can output the warning before postgres # messes it up if [ "$POSTGRES_PASSWORD" ]; then pass="PASSWORD '$POSTGRES_PASSWORD'" @@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then Docker's default configuration, this is effectively any other container on the same system. - + Use "-e POSTGRES_PASSWORD=password" to set it in "docker run". **************************************************** EOWARN - + pass= authMethod=trust fi - + : ${POSTGRES_USER:=postgres} : ${POSTGRES_DB:=$POSTGRES_USER} @@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then EOSQL echo fi - + if [ "$POSTGRES_USER" = 'postgres' ]; then op='ALTER' else @@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; EOSQL echo - + { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf - + if [ -d /docker-entrypoint-initdb.d ]; then for f in /docker-entrypoint-initdb.d/*.sh; do [ -f "$f" ] && . "$f" done fi fi - + exec gosu postgres "$@" fi diff --git a/9.2/docker-entrypoint.sh b/9.2/docker-entrypoint.sh index 27c98d2147..40eb716850 100755 --- a/9.2/docker-entrypoint.sh +++ b/9.2/docker-entrypoint.sh @@ -2,17 +2,19 @@ set -e if [ "$1" = 'postgres' ]; then + mkdir -p "$PGDATA" chown -R postgres "$PGDATA" - + chmod g+s /run/postgresql chown -R postgres:postgres /run/postgresql - - if [ -z "$(ls -A "$PGDATA")" ]; then + + # look specifically for PG_VERSION, as it is expected in the DB dir + if [ -z "$(ls -A "$PGDATA"/PG_VERSION)" ]; then gosu postgres initdb - + sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf - - # check password first so we can ouptut the warning before postgres + + # check password first so we can output the warning before postgres # messes it up if [ "$POSTGRES_PASSWORD" ]; then pass="PASSWORD '$POSTGRES_PASSWORD'" @@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then Docker's default configuration, this is effectively any other container on the same system. - + Use "-e POSTGRES_PASSWORD=password" to set it in "docker run". **************************************************** EOWARN - + pass= authMethod=trust fi - + : ${POSTGRES_USER:=postgres} : ${POSTGRES_DB:=$POSTGRES_USER} @@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then EOSQL echo fi - + if [ "$POSTGRES_USER" = 'postgres' ]; then op='ALTER' else @@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; EOSQL echo - + { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf - + if [ -d /docker-entrypoint-initdb.d ]; then for f in /docker-entrypoint-initdb.d/*.sh; do [ -f "$f" ] && . "$f" done fi fi - + exec gosu postgres "$@" fi diff --git a/9.3/docker-entrypoint.sh b/9.3/docker-entrypoint.sh index 27c98d2147..40eb716850 100755 --- a/9.3/docker-entrypoint.sh +++ b/9.3/docker-entrypoint.sh @@ -2,17 +2,19 @@ set -e if [ "$1" = 'postgres' ]; then + mkdir -p "$PGDATA" chown -R postgres "$PGDATA" - + chmod g+s /run/postgresql chown -R postgres:postgres /run/postgresql - - if [ -z "$(ls -A "$PGDATA")" ]; then + + # look specifically for PG_VERSION, as it is expected in the DB dir + if [ -z "$(ls -A "$PGDATA"/PG_VERSION)" ]; then gosu postgres initdb - + sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf - - # check password first so we can ouptut the warning before postgres + + # check password first so we can output the warning before postgres # messes it up if [ "$POSTGRES_PASSWORD" ]; then pass="PASSWORD '$POSTGRES_PASSWORD'" @@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then Docker's default configuration, this is effectively any other container on the same system. - + Use "-e POSTGRES_PASSWORD=password" to set it in "docker run". **************************************************** EOWARN - + pass= authMethod=trust fi - + : ${POSTGRES_USER:=postgres} : ${POSTGRES_DB:=$POSTGRES_USER} @@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then EOSQL echo fi - + if [ "$POSTGRES_USER" = 'postgres' ]; then op='ALTER' else @@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; EOSQL echo - + { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf - + if [ -d /docker-entrypoint-initdb.d ]; then for f in /docker-entrypoint-initdb.d/*.sh; do [ -f "$f" ] && . "$f" done fi fi - + exec gosu postgres "$@" fi diff --git a/9.4/docker-entrypoint.sh b/9.4/docker-entrypoint.sh index 27c98d2147..40eb716850 100755 --- a/9.4/docker-entrypoint.sh +++ b/9.4/docker-entrypoint.sh @@ -2,17 +2,19 @@ set -e if [ "$1" = 'postgres' ]; then + mkdir -p "$PGDATA" chown -R postgres "$PGDATA" - + chmod g+s /run/postgresql chown -R postgres:postgres /run/postgresql - - if [ -z "$(ls -A "$PGDATA")" ]; then + + # look specifically for PG_VERSION, as it is expected in the DB dir + if [ -z "$(ls -A "$PGDATA"/PG_VERSION)" ]; then gosu postgres initdb - + sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf - - # check password first so we can ouptut the warning before postgres + + # check password first so we can output the warning before postgres # messes it up if [ "$POSTGRES_PASSWORD" ]; then pass="PASSWORD '$POSTGRES_PASSWORD'" @@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then Docker's default configuration, this is effectively any other container on the same system. - + Use "-e POSTGRES_PASSWORD=password" to set it in "docker run". **************************************************** EOWARN - + pass= authMethod=trust fi - + : ${POSTGRES_USER:=postgres} : ${POSTGRES_DB:=$POSTGRES_USER} @@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then EOSQL echo fi - + if [ "$POSTGRES_USER" = 'postgres' ]; then op='ALTER' else @@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; EOSQL echo - + { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf - + if [ -d /docker-entrypoint-initdb.d ]; then for f in /docker-entrypoint-initdb.d/*.sh; do [ -f "$f" ] && . "$f" done fi fi - + exec gosu postgres "$@" fi diff --git a/9.5/docker-entrypoint.sh b/9.5/docker-entrypoint.sh index 27c98d2147..40eb716850 100755 --- a/9.5/docker-entrypoint.sh +++ b/9.5/docker-entrypoint.sh @@ -2,17 +2,19 @@ set -e if [ "$1" = 'postgres' ]; then + mkdir -p "$PGDATA" chown -R postgres "$PGDATA" - + chmod g+s /run/postgresql chown -R postgres:postgres /run/postgresql - - if [ -z "$(ls -A "$PGDATA")" ]; then + + # look specifically for PG_VERSION, as it is expected in the DB dir + if [ -z "$(ls -A "$PGDATA"/PG_VERSION)" ]; then gosu postgres initdb - + sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf - - # check password first so we can ouptut the warning before postgres + + # check password first so we can output the warning before postgres # messes it up if [ "$POSTGRES_PASSWORD" ]; then pass="PASSWORD '$POSTGRES_PASSWORD'" @@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then Docker's default configuration, this is effectively any other container on the same system. - + Use "-e POSTGRES_PASSWORD=password" to set it in "docker run". **************************************************** EOWARN - + pass= authMethod=trust fi - + : ${POSTGRES_USER:=postgres} : ${POSTGRES_DB:=$POSTGRES_USER} @@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then EOSQL echo fi - + if [ "$POSTGRES_USER" = 'postgres' ]; then op='ALTER' else @@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; EOSQL echo - + { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf - + if [ -d /docker-entrypoint-initdb.d ]; then for f in /docker-entrypoint-initdb.d/*.sh; do [ -f "$f" ] && . "$f" done fi fi - + exec gosu postgres "$@" fi diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 27c98d2147..40eb716850 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -2,17 +2,19 @@ set -e if [ "$1" = 'postgres' ]; then + mkdir -p "$PGDATA" chown -R postgres "$PGDATA" - + chmod g+s /run/postgresql chown -R postgres:postgres /run/postgresql - - if [ -z "$(ls -A "$PGDATA")" ]; then + + # look specifically for PG_VERSION, as it is expected in the DB dir + if [ -z "$(ls -A "$PGDATA"/PG_VERSION)" ]; then gosu postgres initdb - + sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf - - # check password first so we can ouptut the warning before postgres + + # check password first so we can output the warning before postgres # messes it up if [ "$POSTGRES_PASSWORD" ]; then pass="PASSWORD '$POSTGRES_PASSWORD'" @@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then Docker's default configuration, this is effectively any other container on the same system. - + Use "-e POSTGRES_PASSWORD=password" to set it in "docker run". **************************************************** EOWARN - + pass= authMethod=trust fi - + : ${POSTGRES_USER:=postgres} : ${POSTGRES_DB:=$POSTGRES_USER} @@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then EOSQL echo fi - + if [ "$POSTGRES_USER" = 'postgres' ]; then op='ALTER' else @@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; EOSQL echo - + { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf - + if [ -d /docker-entrypoint-initdb.d ]; then for f in /docker-entrypoint-initdb.d/*.sh; do [ -f "$f" ] && . "$f" done fi fi - + exec gosu postgres "$@" fi From 9c7bb73021815a17fae056508f54b764d7aefc5b Mon Sep 17 00:00:00 2001 From: Victor Heng Date: Sun, 19 Jul 2015 00:41:18 +0800 Subject: [PATCH 2/2] Check that PG_VERSION is non-empty. --- 9.0/docker-entrypoint.sh | 2 +- 9.1/docker-entrypoint.sh | 2 +- 9.2/docker-entrypoint.sh | 2 +- 9.3/docker-entrypoint.sh | 2 +- 9.4/docker-entrypoint.sh | 2 +- 9.5/docker-entrypoint.sh | 2 +- docker-entrypoint.sh | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/9.0/docker-entrypoint.sh b/9.0/docker-entrypoint.sh index 40eb716850..5691f092cb 100755 --- a/9.0/docker-entrypoint.sh +++ b/9.0/docker-entrypoint.sh @@ -9,7 +9,7 @@ if [ "$1" = 'postgres' ]; then chown -R postgres:postgres /run/postgresql # look specifically for PG_VERSION, as it is expected in the DB dir - if [ -z "$(ls -A "$PGDATA"/PG_VERSION)" ]; then + if [ -s "$PGDATA/PG_VERSION" ]; then gosu postgres initdb sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf diff --git a/9.1/docker-entrypoint.sh b/9.1/docker-entrypoint.sh index 40eb716850..5691f092cb 100755 --- a/9.1/docker-entrypoint.sh +++ b/9.1/docker-entrypoint.sh @@ -9,7 +9,7 @@ if [ "$1" = 'postgres' ]; then chown -R postgres:postgres /run/postgresql # look specifically for PG_VERSION, as it is expected in the DB dir - if [ -z "$(ls -A "$PGDATA"/PG_VERSION)" ]; then + if [ -s "$PGDATA/PG_VERSION" ]; then gosu postgres initdb sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf diff --git a/9.2/docker-entrypoint.sh b/9.2/docker-entrypoint.sh index 40eb716850..5691f092cb 100755 --- a/9.2/docker-entrypoint.sh +++ b/9.2/docker-entrypoint.sh @@ -9,7 +9,7 @@ if [ "$1" = 'postgres' ]; then chown -R postgres:postgres /run/postgresql # look specifically for PG_VERSION, as it is expected in the DB dir - if [ -z "$(ls -A "$PGDATA"/PG_VERSION)" ]; then + if [ -s "$PGDATA/PG_VERSION" ]; then gosu postgres initdb sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf diff --git a/9.3/docker-entrypoint.sh b/9.3/docker-entrypoint.sh index 40eb716850..5691f092cb 100755 --- a/9.3/docker-entrypoint.sh +++ b/9.3/docker-entrypoint.sh @@ -9,7 +9,7 @@ if [ "$1" = 'postgres' ]; then chown -R postgres:postgres /run/postgresql # look specifically for PG_VERSION, as it is expected in the DB dir - if [ -z "$(ls -A "$PGDATA"/PG_VERSION)" ]; then + if [ -s "$PGDATA/PG_VERSION" ]; then gosu postgres initdb sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf diff --git a/9.4/docker-entrypoint.sh b/9.4/docker-entrypoint.sh index 40eb716850..5691f092cb 100755 --- a/9.4/docker-entrypoint.sh +++ b/9.4/docker-entrypoint.sh @@ -9,7 +9,7 @@ if [ "$1" = 'postgres' ]; then chown -R postgres:postgres /run/postgresql # look specifically for PG_VERSION, as it is expected in the DB dir - if [ -z "$(ls -A "$PGDATA"/PG_VERSION)" ]; then + if [ -s "$PGDATA/PG_VERSION" ]; then gosu postgres initdb sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf diff --git a/9.5/docker-entrypoint.sh b/9.5/docker-entrypoint.sh index 40eb716850..5691f092cb 100755 --- a/9.5/docker-entrypoint.sh +++ b/9.5/docker-entrypoint.sh @@ -9,7 +9,7 @@ if [ "$1" = 'postgres' ]; then chown -R postgres:postgres /run/postgresql # look specifically for PG_VERSION, as it is expected in the DB dir - if [ -z "$(ls -A "$PGDATA"/PG_VERSION)" ]; then + if [ -s "$PGDATA/PG_VERSION" ]; then gosu postgres initdb sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 40eb716850..5691f092cb 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -9,7 +9,7 @@ if [ "$1" = 'postgres' ]; then chown -R postgres:postgres /run/postgresql # look specifically for PG_VERSION, as it is expected in the DB dir - if [ -z "$(ls -A "$PGDATA"/PG_VERSION)" ]; then + if [ -s "$PGDATA/PG_VERSION" ]; then gosu postgres initdb sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf