From a7d6b77f66f2ee778a1ca9b855625894fd607d3c Mon Sep 17 00:00:00 2001 From: pranithreddym Date: Mon, 11 May 2026 19:37:20 -0500 Subject: [PATCH] Log which init file failed in docker_process_init_files (fixes #1026) When a script or SQL file in /docker-entrypoint-initdb.d/ fails during container initialization, the container exits but gives no indication of which file caused the error. This makes debugging difficult, especially when many init files are present. Add `|| mysql_error` to every execution path in docker_process_init_files so that on failure the log clearly names the file that failed: [ERROR] [Entrypoint]: entrypoint.sh: failed while running /docker-entrypoint-initdb.d/02_seed.sql Applies to: executable .sh, sourced .sh, .sql, .sql.gz, .sql.bz2, .sql.xz, and .sql.zst file types. --- 8.4/docker-entrypoint.sh | 14 +++++++------- 9.7/docker-entrypoint.sh | 14 +++++++------- docker-entrypoint.sh | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/8.4/docker-entrypoint.sh b/8.4/docker-entrypoint.sh index 884774a91..b894b4f9e 100755 --- a/8.4/docker-entrypoint.sh +++ b/8.4/docker-entrypoint.sh @@ -66,17 +66,17 @@ docker_process_init_files() { # https://github.com/docker-library/postgres/pull/452 if [ -x "$f" ]; then mysql_note "$0: running $f" - "$f" + "$f" || mysql_error "$0: failed while running $f" else mysql_note "$0: sourcing $f" - . "$f" + . "$f" || mysql_error "$0: failed while sourcing $f" fi ;; - *.sql) mysql_note "$0: running $f"; docker_process_sql < "$f"; echo ;; - *.sql.bz2) mysql_note "$0: running $f"; bunzip2 -c "$f" | docker_process_sql; echo ;; - *.sql.gz) mysql_note "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; - *.sql.xz) mysql_note "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; - *.sql.zst) mysql_note "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; + *.sql) mysql_note "$0: running $f"; docker_process_sql < "$f" || mysql_error "$0: failed while running $f"; echo ;; + *.sql.bz2) mysql_note "$0: running $f"; bunzip2 -c "$f" | docker_process_sql || mysql_error "$0: failed while running $f"; echo ;; + *.sql.gz) mysql_note "$0: running $f"; gunzip -c "$f" | docker_process_sql || mysql_error "$0: failed while running $f"; echo ;; + *.sql.xz) mysql_note "$0: running $f"; xzcat "$f" | docker_process_sql || mysql_error "$0: failed while running $f"; echo ;; + *.sql.zst) mysql_note "$0: running $f"; zstd -dc "$f" | docker_process_sql || mysql_error "$0: failed while running $f"; echo ;; *) mysql_warn "$0: ignoring $f" ;; esac echo diff --git a/9.7/docker-entrypoint.sh b/9.7/docker-entrypoint.sh index 884774a91..b894b4f9e 100755 --- a/9.7/docker-entrypoint.sh +++ b/9.7/docker-entrypoint.sh @@ -66,17 +66,17 @@ docker_process_init_files() { # https://github.com/docker-library/postgres/pull/452 if [ -x "$f" ]; then mysql_note "$0: running $f" - "$f" + "$f" || mysql_error "$0: failed while running $f" else mysql_note "$0: sourcing $f" - . "$f" + . "$f" || mysql_error "$0: failed while sourcing $f" fi ;; - *.sql) mysql_note "$0: running $f"; docker_process_sql < "$f"; echo ;; - *.sql.bz2) mysql_note "$0: running $f"; bunzip2 -c "$f" | docker_process_sql; echo ;; - *.sql.gz) mysql_note "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; - *.sql.xz) mysql_note "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; - *.sql.zst) mysql_note "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; + *.sql) mysql_note "$0: running $f"; docker_process_sql < "$f" || mysql_error "$0: failed while running $f"; echo ;; + *.sql.bz2) mysql_note "$0: running $f"; bunzip2 -c "$f" | docker_process_sql || mysql_error "$0: failed while running $f"; echo ;; + *.sql.gz) mysql_note "$0: running $f"; gunzip -c "$f" | docker_process_sql || mysql_error "$0: failed while running $f"; echo ;; + *.sql.xz) mysql_note "$0: running $f"; xzcat "$f" | docker_process_sql || mysql_error "$0: failed while running $f"; echo ;; + *.sql.zst) mysql_note "$0: running $f"; zstd -dc "$f" | docker_process_sql || mysql_error "$0: failed while running $f"; echo ;; *) mysql_warn "$0: ignoring $f" ;; esac echo diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 884774a91..b894b4f9e 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -66,17 +66,17 @@ docker_process_init_files() { # https://github.com/docker-library/postgres/pull/452 if [ -x "$f" ]; then mysql_note "$0: running $f" - "$f" + "$f" || mysql_error "$0: failed while running $f" else mysql_note "$0: sourcing $f" - . "$f" + . "$f" || mysql_error "$0: failed while sourcing $f" fi ;; - *.sql) mysql_note "$0: running $f"; docker_process_sql < "$f"; echo ;; - *.sql.bz2) mysql_note "$0: running $f"; bunzip2 -c "$f" | docker_process_sql; echo ;; - *.sql.gz) mysql_note "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; - *.sql.xz) mysql_note "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; - *.sql.zst) mysql_note "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; + *.sql) mysql_note "$0: running $f"; docker_process_sql < "$f" || mysql_error "$0: failed while running $f"; echo ;; + *.sql.bz2) mysql_note "$0: running $f"; bunzip2 -c "$f" | docker_process_sql || mysql_error "$0: failed while running $f"; echo ;; + *.sql.gz) mysql_note "$0: running $f"; gunzip -c "$f" | docker_process_sql || mysql_error "$0: failed while running $f"; echo ;; + *.sql.xz) mysql_note "$0: running $f"; xzcat "$f" | docker_process_sql || mysql_error "$0: failed while running $f"; echo ;; + *.sql.zst) mysql_note "$0: running $f"; zstd -dc "$f" | docker_process_sql || mysql_error "$0: failed while running $f"; echo ;; *) mysql_warn "$0: ignoring $f" ;; esac echo