From 9a5459382a2bf2a414c8f2a8036b9ae5c0289499 Mon Sep 17 00:00:00 2001 From: Ovidiu Gheorghies Date: Sun, 9 Feb 2020 16:46:08 +0200 Subject: [PATCH] Add support for database update scripts. The files /docker-entrypoint-updatedb.d/* are run every time a container starts, even if the database directory is not empty. This is unlike the files /docker-entrypoint-initdb.d/*, which are only run iif the database directory is empty. When the database directory is empty, the update scripts are run after the init scripts. Suppose that the following files are present in a container image: /docker-entrypoint-initdb.d/init.sh /docker-entrypoint-updatedb.d/update.sh When a new container is run for the first time with a persistent volume, for example as follows: $ docker run --rm -it \ -v ./my-initdb.d:/docker-entrypoint-initdb.d \ -v ./my-updatedb.d:/docker-entrypoint-updatedb.d \ -v my-vol:/var/lib/postgresql/data postgres the following init files are run, in this order: /docker-entrypoint-initdb.d/init.sh /docker-entrypoint-updatedb.d/update.sh If the container is stopped and a new container is started with the same command, only this file is run: /docker-entrypoint-updatedb.d/update.sh --- 10/alpine/docker-entrypoint.sh | 35 +++++++++++++++++++++++---------- 10/docker-entrypoint.sh | 35 +++++++++++++++++++++++---------- 11/alpine/docker-entrypoint.sh | 35 +++++++++++++++++++++++---------- 11/docker-entrypoint.sh | 35 +++++++++++++++++++++++---------- 12/alpine/docker-entrypoint.sh | 35 +++++++++++++++++++++++---------- 12/docker-entrypoint.sh | 35 +++++++++++++++++++++++---------- 9.4/alpine/docker-entrypoint.sh | 35 +++++++++++++++++++++++---------- 9.4/docker-entrypoint.sh | 35 +++++++++++++++++++++++---------- 9.5/alpine/docker-entrypoint.sh | 35 +++++++++++++++++++++++---------- 9.5/docker-entrypoint.sh | 35 +++++++++++++++++++++++---------- 9.6/alpine/docker-entrypoint.sh | 35 +++++++++++++++++++++++---------- 9.6/docker-entrypoint.sh | 35 +++++++++++++++++++++++---------- docker-entrypoint.sh | 35 +++++++++++++++++++++++---------- 13 files changed, 325 insertions(+), 130 deletions(-) diff --git a/10/alpine/docker-entrypoint.sh b/10/alpine/docker-entrypoint.sh index 3498032b00..cf75fc5dcd 100755 --- a/10/alpine/docker-entrypoint.sh +++ b/10/alpine/docker-entrypoint.sh @@ -229,6 +229,21 @@ docker_temp_server_stop() { pg_ctl -D "$PGDATA" -m fast -w stop } +# run stdin lines as individual commands, while a temp server is started +docker_run_with_temp_server() { + # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless + # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS + export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" + docker_temp_server_start "$@" + + while read command; do + ${command} + done + + docker_temp_server_stop + unset PGPASSWORD +} + # check arguments for an option that would cause postgres to stop # return true if there is one _pg_want_help() { @@ -267,16 +282,10 @@ _main() { docker_init_database_dir pg_setup_hba_conf - # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless - # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS - export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" - docker_temp_server_start "$@" - - docker_setup_db - docker_process_init_files /docker-entrypoint-initdb.d/* - - docker_temp_server_stop - unset PGPASSWORD + docker_run_with_temp_server <<-'COMMANDS' + docker_setup_db + docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/* + COMMANDS echo echo 'PostgreSQL init process complete; ready for start up.' @@ -285,6 +294,12 @@ _main() { echo echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization' echo + + if [ -d /docker-entrypoint-updatedb.d/ ]; then + docker_run_with_temp_server <<-'COMMANDS' + docker_process_init_files /docker-entrypoint-updatedb.d/* + COMMANDS + fi fi fi diff --git a/10/docker-entrypoint.sh b/10/docker-entrypoint.sh index 698ce9f48c..6d64bd166a 100755 --- a/10/docker-entrypoint.sh +++ b/10/docker-entrypoint.sh @@ -229,6 +229,21 @@ docker_temp_server_stop() { pg_ctl -D "$PGDATA" -m fast -w stop } +# run stdin lines as individual commands, while a temp server is started +docker_run_with_temp_server() { + # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless + # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS + export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" + docker_temp_server_start "$@" + + while read command; do + ${command} + done + + docker_temp_server_stop + unset PGPASSWORD +} + # check arguments for an option that would cause postgres to stop # return true if there is one _pg_want_help() { @@ -267,16 +282,10 @@ _main() { docker_init_database_dir pg_setup_hba_conf - # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless - # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS - export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" - docker_temp_server_start "$@" - - docker_setup_db - docker_process_init_files /docker-entrypoint-initdb.d/* - - docker_temp_server_stop - unset PGPASSWORD + docker_run_with_temp_server <<-'COMMANDS' + docker_setup_db + docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/* + COMMANDS echo echo 'PostgreSQL init process complete; ready for start up.' @@ -285,6 +294,12 @@ _main() { echo echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization' echo + + if [ -d /docker-entrypoint-updatedb.d/ ]; then + docker_run_with_temp_server <<-'COMMANDS' + docker_process_init_files /docker-entrypoint-updatedb.d/* + COMMANDS + fi fi fi diff --git a/11/alpine/docker-entrypoint.sh b/11/alpine/docker-entrypoint.sh index 3498032b00..cf75fc5dcd 100755 --- a/11/alpine/docker-entrypoint.sh +++ b/11/alpine/docker-entrypoint.sh @@ -229,6 +229,21 @@ docker_temp_server_stop() { pg_ctl -D "$PGDATA" -m fast -w stop } +# run stdin lines as individual commands, while a temp server is started +docker_run_with_temp_server() { + # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless + # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS + export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" + docker_temp_server_start "$@" + + while read command; do + ${command} + done + + docker_temp_server_stop + unset PGPASSWORD +} + # check arguments for an option that would cause postgres to stop # return true if there is one _pg_want_help() { @@ -267,16 +282,10 @@ _main() { docker_init_database_dir pg_setup_hba_conf - # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless - # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS - export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" - docker_temp_server_start "$@" - - docker_setup_db - docker_process_init_files /docker-entrypoint-initdb.d/* - - docker_temp_server_stop - unset PGPASSWORD + docker_run_with_temp_server <<-'COMMANDS' + docker_setup_db + docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/* + COMMANDS echo echo 'PostgreSQL init process complete; ready for start up.' @@ -285,6 +294,12 @@ _main() { echo echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization' echo + + if [ -d /docker-entrypoint-updatedb.d/ ]; then + docker_run_with_temp_server <<-'COMMANDS' + docker_process_init_files /docker-entrypoint-updatedb.d/* + COMMANDS + fi fi fi diff --git a/11/docker-entrypoint.sh b/11/docker-entrypoint.sh index 698ce9f48c..6d64bd166a 100755 --- a/11/docker-entrypoint.sh +++ b/11/docker-entrypoint.sh @@ -229,6 +229,21 @@ docker_temp_server_stop() { pg_ctl -D "$PGDATA" -m fast -w stop } +# run stdin lines as individual commands, while a temp server is started +docker_run_with_temp_server() { + # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless + # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS + export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" + docker_temp_server_start "$@" + + while read command; do + ${command} + done + + docker_temp_server_stop + unset PGPASSWORD +} + # check arguments for an option that would cause postgres to stop # return true if there is one _pg_want_help() { @@ -267,16 +282,10 @@ _main() { docker_init_database_dir pg_setup_hba_conf - # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless - # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS - export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" - docker_temp_server_start "$@" - - docker_setup_db - docker_process_init_files /docker-entrypoint-initdb.d/* - - docker_temp_server_stop - unset PGPASSWORD + docker_run_with_temp_server <<-'COMMANDS' + docker_setup_db + docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/* + COMMANDS echo echo 'PostgreSQL init process complete; ready for start up.' @@ -285,6 +294,12 @@ _main() { echo echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization' echo + + if [ -d /docker-entrypoint-updatedb.d/ ]; then + docker_run_with_temp_server <<-'COMMANDS' + docker_process_init_files /docker-entrypoint-updatedb.d/* + COMMANDS + fi fi fi diff --git a/12/alpine/docker-entrypoint.sh b/12/alpine/docker-entrypoint.sh index 3498032b00..cf75fc5dcd 100755 --- a/12/alpine/docker-entrypoint.sh +++ b/12/alpine/docker-entrypoint.sh @@ -229,6 +229,21 @@ docker_temp_server_stop() { pg_ctl -D "$PGDATA" -m fast -w stop } +# run stdin lines as individual commands, while a temp server is started +docker_run_with_temp_server() { + # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless + # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS + export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" + docker_temp_server_start "$@" + + while read command; do + ${command} + done + + docker_temp_server_stop + unset PGPASSWORD +} + # check arguments for an option that would cause postgres to stop # return true if there is one _pg_want_help() { @@ -267,16 +282,10 @@ _main() { docker_init_database_dir pg_setup_hba_conf - # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless - # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS - export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" - docker_temp_server_start "$@" - - docker_setup_db - docker_process_init_files /docker-entrypoint-initdb.d/* - - docker_temp_server_stop - unset PGPASSWORD + docker_run_with_temp_server <<-'COMMANDS' + docker_setup_db + docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/* + COMMANDS echo echo 'PostgreSQL init process complete; ready for start up.' @@ -285,6 +294,12 @@ _main() { echo echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization' echo + + if [ -d /docker-entrypoint-updatedb.d/ ]; then + docker_run_with_temp_server <<-'COMMANDS' + docker_process_init_files /docker-entrypoint-updatedb.d/* + COMMANDS + fi fi fi diff --git a/12/docker-entrypoint.sh b/12/docker-entrypoint.sh index 698ce9f48c..6d64bd166a 100755 --- a/12/docker-entrypoint.sh +++ b/12/docker-entrypoint.sh @@ -229,6 +229,21 @@ docker_temp_server_stop() { pg_ctl -D "$PGDATA" -m fast -w stop } +# run stdin lines as individual commands, while a temp server is started +docker_run_with_temp_server() { + # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless + # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS + export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" + docker_temp_server_start "$@" + + while read command; do + ${command} + done + + docker_temp_server_stop + unset PGPASSWORD +} + # check arguments for an option that would cause postgres to stop # return true if there is one _pg_want_help() { @@ -267,16 +282,10 @@ _main() { docker_init_database_dir pg_setup_hba_conf - # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless - # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS - export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" - docker_temp_server_start "$@" - - docker_setup_db - docker_process_init_files /docker-entrypoint-initdb.d/* - - docker_temp_server_stop - unset PGPASSWORD + docker_run_with_temp_server <<-'COMMANDS' + docker_setup_db + docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/* + COMMANDS echo echo 'PostgreSQL init process complete; ready for start up.' @@ -285,6 +294,12 @@ _main() { echo echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization' echo + + if [ -d /docker-entrypoint-updatedb.d/ ]; then + docker_run_with_temp_server <<-'COMMANDS' + docker_process_init_files /docker-entrypoint-updatedb.d/* + COMMANDS + fi fi fi diff --git a/9.4/alpine/docker-entrypoint.sh b/9.4/alpine/docker-entrypoint.sh index b86e2fd509..b57388522c 100755 --- a/9.4/alpine/docker-entrypoint.sh +++ b/9.4/alpine/docker-entrypoint.sh @@ -229,6 +229,21 @@ docker_temp_server_stop() { pg_ctl -D "$PGDATA" -m fast -w stop } +# run stdin lines as individual commands, while a temp server is started +docker_run_with_temp_server() { + # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless + # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS + export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" + docker_temp_server_start "$@" + + while read command; do + ${command} + done + + docker_temp_server_stop + unset PGPASSWORD +} + # check arguments for an option that would cause postgres to stop # return true if there is one _pg_want_help() { @@ -267,16 +282,10 @@ _main() { docker_init_database_dir pg_setup_hba_conf - # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless - # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS - export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" - docker_temp_server_start "$@" - - docker_setup_db - docker_process_init_files /docker-entrypoint-initdb.d/* - - docker_temp_server_stop - unset PGPASSWORD + docker_run_with_temp_server <<-'COMMANDS' + docker_setup_db + docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/* + COMMANDS echo echo 'PostgreSQL init process complete; ready for start up.' @@ -285,6 +294,12 @@ _main() { echo echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization' echo + + if [ -d /docker-entrypoint-updatedb.d/ ]; then + docker_run_with_temp_server <<-'COMMANDS' + docker_process_init_files /docker-entrypoint-updatedb.d/* + COMMANDS + fi fi fi diff --git a/9.4/docker-entrypoint.sh b/9.4/docker-entrypoint.sh index cd3140393b..531296a0ca 100755 --- a/9.4/docker-entrypoint.sh +++ b/9.4/docker-entrypoint.sh @@ -229,6 +229,21 @@ docker_temp_server_stop() { pg_ctl -D "$PGDATA" -m fast -w stop } +# run stdin lines as individual commands, while a temp server is started +docker_run_with_temp_server() { + # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless + # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS + export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" + docker_temp_server_start "$@" + + while read command; do + ${command} + done + + docker_temp_server_stop + unset PGPASSWORD +} + # check arguments for an option that would cause postgres to stop # return true if there is one _pg_want_help() { @@ -267,16 +282,10 @@ _main() { docker_init_database_dir pg_setup_hba_conf - # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless - # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS - export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" - docker_temp_server_start "$@" - - docker_setup_db - docker_process_init_files /docker-entrypoint-initdb.d/* - - docker_temp_server_stop - unset PGPASSWORD + docker_run_with_temp_server <<-'COMMANDS' + docker_setup_db + docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/* + COMMANDS echo echo 'PostgreSQL init process complete; ready for start up.' @@ -285,6 +294,12 @@ _main() { echo echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization' echo + + if [ -d /docker-entrypoint-updatedb.d/ ]; then + docker_run_with_temp_server <<-'COMMANDS' + docker_process_init_files /docker-entrypoint-updatedb.d/* + COMMANDS + fi fi fi diff --git a/9.5/alpine/docker-entrypoint.sh b/9.5/alpine/docker-entrypoint.sh index b86e2fd509..b57388522c 100755 --- a/9.5/alpine/docker-entrypoint.sh +++ b/9.5/alpine/docker-entrypoint.sh @@ -229,6 +229,21 @@ docker_temp_server_stop() { pg_ctl -D "$PGDATA" -m fast -w stop } +# run stdin lines as individual commands, while a temp server is started +docker_run_with_temp_server() { + # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless + # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS + export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" + docker_temp_server_start "$@" + + while read command; do + ${command} + done + + docker_temp_server_stop + unset PGPASSWORD +} + # check arguments for an option that would cause postgres to stop # return true if there is one _pg_want_help() { @@ -267,16 +282,10 @@ _main() { docker_init_database_dir pg_setup_hba_conf - # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless - # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS - export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" - docker_temp_server_start "$@" - - docker_setup_db - docker_process_init_files /docker-entrypoint-initdb.d/* - - docker_temp_server_stop - unset PGPASSWORD + docker_run_with_temp_server <<-'COMMANDS' + docker_setup_db + docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/* + COMMANDS echo echo 'PostgreSQL init process complete; ready for start up.' @@ -285,6 +294,12 @@ _main() { echo echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization' echo + + if [ -d /docker-entrypoint-updatedb.d/ ]; then + docker_run_with_temp_server <<-'COMMANDS' + docker_process_init_files /docker-entrypoint-updatedb.d/* + COMMANDS + fi fi fi diff --git a/9.5/docker-entrypoint.sh b/9.5/docker-entrypoint.sh index cd3140393b..531296a0ca 100755 --- a/9.5/docker-entrypoint.sh +++ b/9.5/docker-entrypoint.sh @@ -229,6 +229,21 @@ docker_temp_server_stop() { pg_ctl -D "$PGDATA" -m fast -w stop } +# run stdin lines as individual commands, while a temp server is started +docker_run_with_temp_server() { + # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless + # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS + export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" + docker_temp_server_start "$@" + + while read command; do + ${command} + done + + docker_temp_server_stop + unset PGPASSWORD +} + # check arguments for an option that would cause postgres to stop # return true if there is one _pg_want_help() { @@ -267,16 +282,10 @@ _main() { docker_init_database_dir pg_setup_hba_conf - # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless - # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS - export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" - docker_temp_server_start "$@" - - docker_setup_db - docker_process_init_files /docker-entrypoint-initdb.d/* - - docker_temp_server_stop - unset PGPASSWORD + docker_run_with_temp_server <<-'COMMANDS' + docker_setup_db + docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/* + COMMANDS echo echo 'PostgreSQL init process complete; ready for start up.' @@ -285,6 +294,12 @@ _main() { echo echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization' echo + + if [ -d /docker-entrypoint-updatedb.d/ ]; then + docker_run_with_temp_server <<-'COMMANDS' + docker_process_init_files /docker-entrypoint-updatedb.d/* + COMMANDS + fi fi fi diff --git a/9.6/alpine/docker-entrypoint.sh b/9.6/alpine/docker-entrypoint.sh index b86e2fd509..b57388522c 100755 --- a/9.6/alpine/docker-entrypoint.sh +++ b/9.6/alpine/docker-entrypoint.sh @@ -229,6 +229,21 @@ docker_temp_server_stop() { pg_ctl -D "$PGDATA" -m fast -w stop } +# run stdin lines as individual commands, while a temp server is started +docker_run_with_temp_server() { + # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless + # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS + export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" + docker_temp_server_start "$@" + + while read command; do + ${command} + done + + docker_temp_server_stop + unset PGPASSWORD +} + # check arguments for an option that would cause postgres to stop # return true if there is one _pg_want_help() { @@ -267,16 +282,10 @@ _main() { docker_init_database_dir pg_setup_hba_conf - # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless - # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS - export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" - docker_temp_server_start "$@" - - docker_setup_db - docker_process_init_files /docker-entrypoint-initdb.d/* - - docker_temp_server_stop - unset PGPASSWORD + docker_run_with_temp_server <<-'COMMANDS' + docker_setup_db + docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/* + COMMANDS echo echo 'PostgreSQL init process complete; ready for start up.' @@ -285,6 +294,12 @@ _main() { echo echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization' echo + + if [ -d /docker-entrypoint-updatedb.d/ ]; then + docker_run_with_temp_server <<-'COMMANDS' + docker_process_init_files /docker-entrypoint-updatedb.d/* + COMMANDS + fi fi fi diff --git a/9.6/docker-entrypoint.sh b/9.6/docker-entrypoint.sh index cd3140393b..531296a0ca 100755 --- a/9.6/docker-entrypoint.sh +++ b/9.6/docker-entrypoint.sh @@ -229,6 +229,21 @@ docker_temp_server_stop() { pg_ctl -D "$PGDATA" -m fast -w stop } +# run stdin lines as individual commands, while a temp server is started +docker_run_with_temp_server() { + # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless + # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS + export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" + docker_temp_server_start "$@" + + while read command; do + ${command} + done + + docker_temp_server_stop + unset PGPASSWORD +} + # check arguments for an option that would cause postgres to stop # return true if there is one _pg_want_help() { @@ -267,16 +282,10 @@ _main() { docker_init_database_dir pg_setup_hba_conf - # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless - # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS - export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" - docker_temp_server_start "$@" - - docker_setup_db - docker_process_init_files /docker-entrypoint-initdb.d/* - - docker_temp_server_stop - unset PGPASSWORD + docker_run_with_temp_server <<-'COMMANDS' + docker_setup_db + docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/* + COMMANDS echo echo 'PostgreSQL init process complete; ready for start up.' @@ -285,6 +294,12 @@ _main() { echo echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization' echo + + if [ -d /docker-entrypoint-updatedb.d/ ]; then + docker_run_with_temp_server <<-'COMMANDS' + docker_process_init_files /docker-entrypoint-updatedb.d/* + COMMANDS + fi fi fi diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 698ce9f48c..6d64bd166a 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -229,6 +229,21 @@ docker_temp_server_stop() { pg_ctl -D "$PGDATA" -m fast -w stop } +# run stdin lines as individual commands, while a temp server is started +docker_run_with_temp_server() { + # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless + # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS + export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" + docker_temp_server_start "$@" + + while read command; do + ${command} + done + + docker_temp_server_stop + unset PGPASSWORD +} + # check arguments for an option that would cause postgres to stop # return true if there is one _pg_want_help() { @@ -267,16 +282,10 @@ _main() { docker_init_database_dir pg_setup_hba_conf - # PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless - # e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS - export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" - docker_temp_server_start "$@" - - docker_setup_db - docker_process_init_files /docker-entrypoint-initdb.d/* - - docker_temp_server_stop - unset PGPASSWORD + docker_run_with_temp_server <<-'COMMANDS' + docker_setup_db + docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/* + COMMANDS echo echo 'PostgreSQL init process complete; ready for start up.' @@ -285,6 +294,12 @@ _main() { echo echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization' echo + + if [ -d /docker-entrypoint-updatedb.d/ ]; then + docker_run_with_temp_server <<-'COMMANDS' + docker_process_init_files /docker-entrypoint-updatedb.d/* + COMMANDS + fi fi fi