From 89530f602087179e8dfbc2aa55621922a278497b Mon Sep 17 00:00:00 2001 From: Daniel Dent Date: Sat, 19 Nov 2016 23:32:41 -0800 Subject: [PATCH 1/2] POSTGRES_INITDB_XLOGDIR to specify xlog log dir Adds support for the POSTGRES_INITDB_XLOGDIR environment variable, which specifies where the postgres transaction log is stored. For some use cases, being able to place the transaction log on a different volume is useful. Existing support for providing flags via $POSTGRES_INITDB_ARGS is inadequate because of the need to create and chown/chmod the directory prior to running initdb. --- 9.2/alpine/docker-entrypoint.sh | 9 +++++++++ 9.2/docker-entrypoint.sh | 9 +++++++++ 9.3/alpine/docker-entrypoint.sh | 9 +++++++++ 9.3/docker-entrypoint.sh | 9 +++++++++ 9.4/alpine/docker-entrypoint.sh | 9 +++++++++ 9.4/docker-entrypoint.sh | 9 +++++++++ 9.5/alpine/docker-entrypoint.sh | 9 +++++++++ 9.5/docker-entrypoint.sh | 9 +++++++++ 9.6/alpine/docker-entrypoint.sh | 9 +++++++++ 9.6/docker-entrypoint.sh | 9 +++++++++ docker-entrypoint.sh | 9 +++++++++ 11 files changed, 99 insertions(+) diff --git a/9.2/alpine/docker-entrypoint.sh b/9.2/alpine/docker-entrypoint.sh index 0ec0bdd54e..4ff7d826f7 100755 --- a/9.2/alpine/docker-entrypoint.sh +++ b/9.2/alpine/docker-entrypoint.sh @@ -37,6 +37,15 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chown -R postgres /var/run/postgresql chmod g+s /var/run/postgresql + # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user + file_env 'POSTGRES_INITDB_XLOGDIR' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + mkdir -p "$POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" + chown -R postgres "$POSTGRES_INITDB_XLOGDIR" + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi + exec su-exec postgres "$BASH_SOURCE" "$@" fi diff --git a/9.2/docker-entrypoint.sh b/9.2/docker-entrypoint.sh index 66ea0f1d94..a4c9e300bb 100755 --- a/9.2/docker-entrypoint.sh +++ b/9.2/docker-entrypoint.sh @@ -37,6 +37,15 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chown -R postgres /var/run/postgresql chmod g+s /var/run/postgresql + # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user + file_env 'POSTGRES_INITDB_XLOGDIR' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + mkdir -p "$POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" + chown -R postgres "$POSTGRES_INITDB_XLOGDIR" + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi + exec gosu postgres "$BASH_SOURCE" "$@" fi diff --git a/9.3/alpine/docker-entrypoint.sh b/9.3/alpine/docker-entrypoint.sh index 0ec0bdd54e..4ff7d826f7 100755 --- a/9.3/alpine/docker-entrypoint.sh +++ b/9.3/alpine/docker-entrypoint.sh @@ -37,6 +37,15 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chown -R postgres /var/run/postgresql chmod g+s /var/run/postgresql + # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user + file_env 'POSTGRES_INITDB_XLOGDIR' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + mkdir -p "$POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" + chown -R postgres "$POSTGRES_INITDB_XLOGDIR" + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi + exec su-exec postgres "$BASH_SOURCE" "$@" fi diff --git a/9.3/docker-entrypoint.sh b/9.3/docker-entrypoint.sh index 66ea0f1d94..a4c9e300bb 100755 --- a/9.3/docker-entrypoint.sh +++ b/9.3/docker-entrypoint.sh @@ -37,6 +37,15 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chown -R postgres /var/run/postgresql chmod g+s /var/run/postgresql + # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user + file_env 'POSTGRES_INITDB_XLOGDIR' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + mkdir -p "$POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" + chown -R postgres "$POSTGRES_INITDB_XLOGDIR" + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi + exec gosu postgres "$BASH_SOURCE" "$@" fi diff --git a/9.4/alpine/docker-entrypoint.sh b/9.4/alpine/docker-entrypoint.sh index 0ec0bdd54e..4ff7d826f7 100755 --- a/9.4/alpine/docker-entrypoint.sh +++ b/9.4/alpine/docker-entrypoint.sh @@ -37,6 +37,15 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chown -R postgres /var/run/postgresql chmod g+s /var/run/postgresql + # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user + file_env 'POSTGRES_INITDB_XLOGDIR' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + mkdir -p "$POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" + chown -R postgres "$POSTGRES_INITDB_XLOGDIR" + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi + exec su-exec postgres "$BASH_SOURCE" "$@" fi diff --git a/9.4/docker-entrypoint.sh b/9.4/docker-entrypoint.sh index 66ea0f1d94..a4c9e300bb 100755 --- a/9.4/docker-entrypoint.sh +++ b/9.4/docker-entrypoint.sh @@ -37,6 +37,15 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chown -R postgres /var/run/postgresql chmod g+s /var/run/postgresql + # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user + file_env 'POSTGRES_INITDB_XLOGDIR' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + mkdir -p "$POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" + chown -R postgres "$POSTGRES_INITDB_XLOGDIR" + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi + exec gosu postgres "$BASH_SOURCE" "$@" fi diff --git a/9.5/alpine/docker-entrypoint.sh b/9.5/alpine/docker-entrypoint.sh index 0ec0bdd54e..4ff7d826f7 100755 --- a/9.5/alpine/docker-entrypoint.sh +++ b/9.5/alpine/docker-entrypoint.sh @@ -37,6 +37,15 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chown -R postgres /var/run/postgresql chmod g+s /var/run/postgresql + # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user + file_env 'POSTGRES_INITDB_XLOGDIR' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + mkdir -p "$POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" + chown -R postgres "$POSTGRES_INITDB_XLOGDIR" + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi + exec su-exec postgres "$BASH_SOURCE" "$@" fi diff --git a/9.5/docker-entrypoint.sh b/9.5/docker-entrypoint.sh index 66ea0f1d94..a4c9e300bb 100755 --- a/9.5/docker-entrypoint.sh +++ b/9.5/docker-entrypoint.sh @@ -37,6 +37,15 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chown -R postgres /var/run/postgresql chmod g+s /var/run/postgresql + # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user + file_env 'POSTGRES_INITDB_XLOGDIR' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + mkdir -p "$POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" + chown -R postgres "$POSTGRES_INITDB_XLOGDIR" + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi + exec gosu postgres "$BASH_SOURCE" "$@" fi diff --git a/9.6/alpine/docker-entrypoint.sh b/9.6/alpine/docker-entrypoint.sh index 0ec0bdd54e..4ff7d826f7 100755 --- a/9.6/alpine/docker-entrypoint.sh +++ b/9.6/alpine/docker-entrypoint.sh @@ -37,6 +37,15 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chown -R postgres /var/run/postgresql chmod g+s /var/run/postgresql + # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user + file_env 'POSTGRES_INITDB_XLOGDIR' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + mkdir -p "$POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" + chown -R postgres "$POSTGRES_INITDB_XLOGDIR" + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi + exec su-exec postgres "$BASH_SOURCE" "$@" fi diff --git a/9.6/docker-entrypoint.sh b/9.6/docker-entrypoint.sh index 66ea0f1d94..a4c9e300bb 100755 --- a/9.6/docker-entrypoint.sh +++ b/9.6/docker-entrypoint.sh @@ -37,6 +37,15 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chown -R postgres /var/run/postgresql chmod g+s /var/run/postgresql + # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user + file_env 'POSTGRES_INITDB_XLOGDIR' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + mkdir -p "$POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" + chown -R postgres "$POSTGRES_INITDB_XLOGDIR" + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi + exec gosu postgres "$BASH_SOURCE" "$@" fi diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 66ea0f1d94..a4c9e300bb 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -37,6 +37,15 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chown -R postgres /var/run/postgresql chmod g+s /var/run/postgresql + # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user + file_env 'POSTGRES_INITDB_XLOGDIR' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + mkdir -p "$POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" + chown -R postgres "$POSTGRES_INITDB_XLOGDIR" + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi + exec gosu postgres "$BASH_SOURCE" "$@" fi From 913bc48bfdccab58c6c15f11841da5146e7bf968 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Mon, 20 Mar 2017 09:50:24 -0700 Subject: [PATCH 2/2] Update order to match other blocks and move "--xlogdir" handling down to where it'll be invoked regardless of our "root" status --- 9.2/alpine/docker-entrypoint.sh | 7 ++++--- 9.2/docker-entrypoint.sh | 7 ++++--- 9.3/alpine/docker-entrypoint.sh | 7 ++++--- 9.3/docker-entrypoint.sh | 7 ++++--- 9.4/alpine/docker-entrypoint.sh | 7 ++++--- 9.4/docker-entrypoint.sh | 7 ++++--- 9.5/alpine/docker-entrypoint.sh | 7 ++++--- 9.5/docker-entrypoint.sh | 7 ++++--- 9.6/alpine/docker-entrypoint.sh | 7 ++++--- 9.6/docker-entrypoint.sh | 7 ++++--- docker-entrypoint.sh | 7 ++++--- 11 files changed, 44 insertions(+), 33 deletions(-) diff --git a/9.2/alpine/docker-entrypoint.sh b/9.2/alpine/docker-entrypoint.sh index 4ff7d826f7..0b0af0d7e0 100755 --- a/9.2/alpine/docker-entrypoint.sh +++ b/9.2/alpine/docker-entrypoint.sh @@ -38,12 +38,10 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chmod g+s /var/run/postgresql # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user - file_env 'POSTGRES_INITDB_XLOGDIR' if [ "$POSTGRES_INITDB_XLOGDIR" ]; then mkdir -p "$POSTGRES_INITDB_XLOGDIR" - chmod 700 "$POSTGRES_INITDB_XLOGDIR" chown -R postgres "$POSTGRES_INITDB_XLOGDIR" - export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" fi exec su-exec postgres "$BASH_SOURCE" "$@" @@ -57,6 +55,9 @@ if [ "$1" = 'postgres' ]; then # look specifically for PG_VERSION, as it is expected in the DB dir if [ ! -s "$PGDATA/PG_VERSION" ]; then file_env 'POSTGRES_INITDB_ARGS' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi eval "initdb --username=postgres $POSTGRES_INITDB_ARGS" # check password first so we can output the warning before postgres diff --git a/9.2/docker-entrypoint.sh b/9.2/docker-entrypoint.sh index a4c9e300bb..6b18e8b1a5 100755 --- a/9.2/docker-entrypoint.sh +++ b/9.2/docker-entrypoint.sh @@ -38,12 +38,10 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chmod g+s /var/run/postgresql # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user - file_env 'POSTGRES_INITDB_XLOGDIR' if [ "$POSTGRES_INITDB_XLOGDIR" ]; then mkdir -p "$POSTGRES_INITDB_XLOGDIR" - chmod 700 "$POSTGRES_INITDB_XLOGDIR" chown -R postgres "$POSTGRES_INITDB_XLOGDIR" - export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" fi exec gosu postgres "$BASH_SOURCE" "$@" @@ -57,6 +55,9 @@ if [ "$1" = 'postgres' ]; then # look specifically for PG_VERSION, as it is expected in the DB dir if [ ! -s "$PGDATA/PG_VERSION" ]; then file_env 'POSTGRES_INITDB_ARGS' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi eval "initdb --username=postgres $POSTGRES_INITDB_ARGS" # check password first so we can output the warning before postgres diff --git a/9.3/alpine/docker-entrypoint.sh b/9.3/alpine/docker-entrypoint.sh index 4ff7d826f7..0b0af0d7e0 100755 --- a/9.3/alpine/docker-entrypoint.sh +++ b/9.3/alpine/docker-entrypoint.sh @@ -38,12 +38,10 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chmod g+s /var/run/postgresql # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user - file_env 'POSTGRES_INITDB_XLOGDIR' if [ "$POSTGRES_INITDB_XLOGDIR" ]; then mkdir -p "$POSTGRES_INITDB_XLOGDIR" - chmod 700 "$POSTGRES_INITDB_XLOGDIR" chown -R postgres "$POSTGRES_INITDB_XLOGDIR" - export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" fi exec su-exec postgres "$BASH_SOURCE" "$@" @@ -57,6 +55,9 @@ if [ "$1" = 'postgres' ]; then # look specifically for PG_VERSION, as it is expected in the DB dir if [ ! -s "$PGDATA/PG_VERSION" ]; then file_env 'POSTGRES_INITDB_ARGS' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi eval "initdb --username=postgres $POSTGRES_INITDB_ARGS" # check password first so we can output the warning before postgres diff --git a/9.3/docker-entrypoint.sh b/9.3/docker-entrypoint.sh index a4c9e300bb..6b18e8b1a5 100755 --- a/9.3/docker-entrypoint.sh +++ b/9.3/docker-entrypoint.sh @@ -38,12 +38,10 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chmod g+s /var/run/postgresql # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user - file_env 'POSTGRES_INITDB_XLOGDIR' if [ "$POSTGRES_INITDB_XLOGDIR" ]; then mkdir -p "$POSTGRES_INITDB_XLOGDIR" - chmod 700 "$POSTGRES_INITDB_XLOGDIR" chown -R postgres "$POSTGRES_INITDB_XLOGDIR" - export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" fi exec gosu postgres "$BASH_SOURCE" "$@" @@ -57,6 +55,9 @@ if [ "$1" = 'postgres' ]; then # look specifically for PG_VERSION, as it is expected in the DB dir if [ ! -s "$PGDATA/PG_VERSION" ]; then file_env 'POSTGRES_INITDB_ARGS' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi eval "initdb --username=postgres $POSTGRES_INITDB_ARGS" # check password first so we can output the warning before postgres diff --git a/9.4/alpine/docker-entrypoint.sh b/9.4/alpine/docker-entrypoint.sh index 4ff7d826f7..0b0af0d7e0 100755 --- a/9.4/alpine/docker-entrypoint.sh +++ b/9.4/alpine/docker-entrypoint.sh @@ -38,12 +38,10 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chmod g+s /var/run/postgresql # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user - file_env 'POSTGRES_INITDB_XLOGDIR' if [ "$POSTGRES_INITDB_XLOGDIR" ]; then mkdir -p "$POSTGRES_INITDB_XLOGDIR" - chmod 700 "$POSTGRES_INITDB_XLOGDIR" chown -R postgres "$POSTGRES_INITDB_XLOGDIR" - export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" fi exec su-exec postgres "$BASH_SOURCE" "$@" @@ -57,6 +55,9 @@ if [ "$1" = 'postgres' ]; then # look specifically for PG_VERSION, as it is expected in the DB dir if [ ! -s "$PGDATA/PG_VERSION" ]; then file_env 'POSTGRES_INITDB_ARGS' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi eval "initdb --username=postgres $POSTGRES_INITDB_ARGS" # check password first so we can output the warning before postgres diff --git a/9.4/docker-entrypoint.sh b/9.4/docker-entrypoint.sh index a4c9e300bb..6b18e8b1a5 100755 --- a/9.4/docker-entrypoint.sh +++ b/9.4/docker-entrypoint.sh @@ -38,12 +38,10 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chmod g+s /var/run/postgresql # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user - file_env 'POSTGRES_INITDB_XLOGDIR' if [ "$POSTGRES_INITDB_XLOGDIR" ]; then mkdir -p "$POSTGRES_INITDB_XLOGDIR" - chmod 700 "$POSTGRES_INITDB_XLOGDIR" chown -R postgres "$POSTGRES_INITDB_XLOGDIR" - export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" fi exec gosu postgres "$BASH_SOURCE" "$@" @@ -57,6 +55,9 @@ if [ "$1" = 'postgres' ]; then # look specifically for PG_VERSION, as it is expected in the DB dir if [ ! -s "$PGDATA/PG_VERSION" ]; then file_env 'POSTGRES_INITDB_ARGS' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi eval "initdb --username=postgres $POSTGRES_INITDB_ARGS" # check password first so we can output the warning before postgres diff --git a/9.5/alpine/docker-entrypoint.sh b/9.5/alpine/docker-entrypoint.sh index 4ff7d826f7..0b0af0d7e0 100755 --- a/9.5/alpine/docker-entrypoint.sh +++ b/9.5/alpine/docker-entrypoint.sh @@ -38,12 +38,10 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chmod g+s /var/run/postgresql # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user - file_env 'POSTGRES_INITDB_XLOGDIR' if [ "$POSTGRES_INITDB_XLOGDIR" ]; then mkdir -p "$POSTGRES_INITDB_XLOGDIR" - chmod 700 "$POSTGRES_INITDB_XLOGDIR" chown -R postgres "$POSTGRES_INITDB_XLOGDIR" - export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" fi exec su-exec postgres "$BASH_SOURCE" "$@" @@ -57,6 +55,9 @@ if [ "$1" = 'postgres' ]; then # look specifically for PG_VERSION, as it is expected in the DB dir if [ ! -s "$PGDATA/PG_VERSION" ]; then file_env 'POSTGRES_INITDB_ARGS' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi eval "initdb --username=postgres $POSTGRES_INITDB_ARGS" # check password first so we can output the warning before postgres diff --git a/9.5/docker-entrypoint.sh b/9.5/docker-entrypoint.sh index a4c9e300bb..6b18e8b1a5 100755 --- a/9.5/docker-entrypoint.sh +++ b/9.5/docker-entrypoint.sh @@ -38,12 +38,10 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chmod g+s /var/run/postgresql # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user - file_env 'POSTGRES_INITDB_XLOGDIR' if [ "$POSTGRES_INITDB_XLOGDIR" ]; then mkdir -p "$POSTGRES_INITDB_XLOGDIR" - chmod 700 "$POSTGRES_INITDB_XLOGDIR" chown -R postgres "$POSTGRES_INITDB_XLOGDIR" - export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" fi exec gosu postgres "$BASH_SOURCE" "$@" @@ -57,6 +55,9 @@ if [ "$1" = 'postgres' ]; then # look specifically for PG_VERSION, as it is expected in the DB dir if [ ! -s "$PGDATA/PG_VERSION" ]; then file_env 'POSTGRES_INITDB_ARGS' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi eval "initdb --username=postgres $POSTGRES_INITDB_ARGS" # check password first so we can output the warning before postgres diff --git a/9.6/alpine/docker-entrypoint.sh b/9.6/alpine/docker-entrypoint.sh index 4ff7d826f7..0b0af0d7e0 100755 --- a/9.6/alpine/docker-entrypoint.sh +++ b/9.6/alpine/docker-entrypoint.sh @@ -38,12 +38,10 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chmod g+s /var/run/postgresql # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user - file_env 'POSTGRES_INITDB_XLOGDIR' if [ "$POSTGRES_INITDB_XLOGDIR" ]; then mkdir -p "$POSTGRES_INITDB_XLOGDIR" - chmod 700 "$POSTGRES_INITDB_XLOGDIR" chown -R postgres "$POSTGRES_INITDB_XLOGDIR" - export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" fi exec su-exec postgres "$BASH_SOURCE" "$@" @@ -57,6 +55,9 @@ if [ "$1" = 'postgres' ]; then # look specifically for PG_VERSION, as it is expected in the DB dir if [ ! -s "$PGDATA/PG_VERSION" ]; then file_env 'POSTGRES_INITDB_ARGS' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi eval "initdb --username=postgres $POSTGRES_INITDB_ARGS" # check password first so we can output the warning before postgres diff --git a/9.6/docker-entrypoint.sh b/9.6/docker-entrypoint.sh index a4c9e300bb..6b18e8b1a5 100755 --- a/9.6/docker-entrypoint.sh +++ b/9.6/docker-entrypoint.sh @@ -38,12 +38,10 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chmod g+s /var/run/postgresql # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user - file_env 'POSTGRES_INITDB_XLOGDIR' if [ "$POSTGRES_INITDB_XLOGDIR" ]; then mkdir -p "$POSTGRES_INITDB_XLOGDIR" - chmod 700 "$POSTGRES_INITDB_XLOGDIR" chown -R postgres "$POSTGRES_INITDB_XLOGDIR" - export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" fi exec gosu postgres "$BASH_SOURCE" "$@" @@ -57,6 +55,9 @@ if [ "$1" = 'postgres' ]; then # look specifically for PG_VERSION, as it is expected in the DB dir if [ ! -s "$PGDATA/PG_VERSION" ]; then file_env 'POSTGRES_INITDB_ARGS' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi eval "initdb --username=postgres $POSTGRES_INITDB_ARGS" # check password first so we can output the warning before postgres diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index a4c9e300bb..6b18e8b1a5 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -38,12 +38,10 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then chmod g+s /var/run/postgresql # Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user - file_env 'POSTGRES_INITDB_XLOGDIR' if [ "$POSTGRES_INITDB_XLOGDIR" ]; then mkdir -p "$POSTGRES_INITDB_XLOGDIR" - chmod 700 "$POSTGRES_INITDB_XLOGDIR" chown -R postgres "$POSTGRES_INITDB_XLOGDIR" - export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + chmod 700 "$POSTGRES_INITDB_XLOGDIR" fi exec gosu postgres "$BASH_SOURCE" "$@" @@ -57,6 +55,9 @@ if [ "$1" = 'postgres' ]; then # look specifically for PG_VERSION, as it is expected in the DB dir if [ ! -s "$PGDATA/PG_VERSION" ]; then file_env 'POSTGRES_INITDB_ARGS' + if [ "$POSTGRES_INITDB_XLOGDIR" ]; then + export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR" + fi eval "initdb --username=postgres $POSTGRES_INITDB_ARGS" # check password first so we can output the warning before postgres