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