From a1fce0d0241c668ab446223698e0f872997a20f3 Mon Sep 17 00:00:00 2001 From: Joe Ferguson Date: Fri, 30 Sep 2016 13:59:02 -0700 Subject: [PATCH 1/2] catch errors before scraping datadir from help output --- 5.5/docker-entrypoint.sh | 19 ++++++++++++++++++- 5.6/docker-entrypoint.sh | 19 ++++++++++++++++++- 5.7/docker-entrypoint.sh | 17 +++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/5.5/docker-entrypoint.sh b/5.5/docker-entrypoint.sh index 9edef2331..a9670b6f2 100755 --- a/5.5/docker-entrypoint.sh +++ b/5.5/docker-entrypoint.sh @@ -18,12 +18,27 @@ for arg; do esac done +_check_config() { + toRun=( "$@" --verbose --help --log-bin-index="$(mktemp -u)" ) + if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then + cat >&2 <<-EOM + + ERROR: mysqld failed while attempting to determine datadir + command was: "${toRun[*]}" + + $errors + EOM + exit 1 + fi +} + _datadir() { - "$@" --verbose --help --log-bin-index=`mktemp -u` 2>/dev/null | awk '$1 == "datadir" { print $2; exit }' + "$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "datadir" { print $2; exit }' } # allow the container to be started with `--user` if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then + _check_config "$@" DATADIR="$(_datadir "$@")" mkdir -p "$DATADIR" chown -R mysql:mysql "$DATADIR" @@ -31,6 +46,8 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then fi if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then + # still need to check config, container may have started with --user + _check_config "$@" # Get config DATADIR="$(_datadir "$@")" diff --git a/5.6/docker-entrypoint.sh b/5.6/docker-entrypoint.sh index a84c751be..cb355e07c 100755 --- a/5.6/docker-entrypoint.sh +++ b/5.6/docker-entrypoint.sh @@ -18,12 +18,27 @@ for arg; do esac done +_check_config() { + toRun=( "$@" --verbose --help --log-bin-index="$(mktemp -u)" ) + if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then + cat >&2 <<-EOM + + ERROR: mysqld failed while attempting to determine datadir + command was: "${toRun[*]}" + + $errors + EOM + exit 1 + fi +} + _datadir() { - "$@" --verbose --help --log-bin-index=`mktemp -u` 2>/dev/null | awk '$1 == "datadir" { print $2; exit }' + "$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "datadir" { print $2; exit }' } # allow the container to be started with `--user` if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then + _check_config "$@" DATADIR="$(_datadir "$@")" mkdir -p "$DATADIR" chown -R mysql:mysql "$DATADIR" @@ -31,6 +46,8 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then fi if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then + # still need to check config, container may have started with --user + _check_config "$@" # Get config DATADIR="$(_datadir "$@")" diff --git a/5.7/docker-entrypoint.sh b/5.7/docker-entrypoint.sh index b909543c6..b298781ec 100755 --- a/5.7/docker-entrypoint.sh +++ b/5.7/docker-entrypoint.sh @@ -18,12 +18,27 @@ for arg; do esac done +_check_config() { + toRun=( "$@" --verbose --help ) + if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then + cat >&2 <<-EOM + + ERROR: mysqld failed while attempting to determine datadir + command was: "${toRun[*]}" + + $errors + EOM + exit 1 + fi +} + _datadir() { "$@" --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }' } # allow the container to be started with `--user` if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then + _check_config "$@" DATADIR="$(_datadir "$@")" mkdir -p "$DATADIR" chown -R mysql:mysql "$DATADIR" @@ -31,6 +46,8 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then fi if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then + # still need to check config, container may have started with --user + _check_config "$@" # Get config DATADIR="$(_datadir "$@")" From bdd76e51397a9600f7fc08761d70ae6ae3c9320c Mon Sep 17 00:00:00 2001 From: Joe Ferguson Date: Fri, 7 Oct 2016 16:02:43 -0700 Subject: [PATCH 2/2] Reword error message in _check_config --- 5.5/docker-entrypoint.sh | 2 +- 5.6/docker-entrypoint.sh | 2 +- 5.7/docker-entrypoint.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/5.5/docker-entrypoint.sh b/5.5/docker-entrypoint.sh index a9670b6f2..71fa618aa 100755 --- a/5.5/docker-entrypoint.sh +++ b/5.5/docker-entrypoint.sh @@ -23,7 +23,7 @@ _check_config() { if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then cat >&2 <<-EOM - ERROR: mysqld failed while attempting to determine datadir + ERROR: mysqld failed while attempting to check config command was: "${toRun[*]}" $errors diff --git a/5.6/docker-entrypoint.sh b/5.6/docker-entrypoint.sh index cb355e07c..30b5965d7 100755 --- a/5.6/docker-entrypoint.sh +++ b/5.6/docker-entrypoint.sh @@ -23,7 +23,7 @@ _check_config() { if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then cat >&2 <<-EOM - ERROR: mysqld failed while attempting to determine datadir + ERROR: mysqld failed while attempting to check config command was: "${toRun[*]}" $errors diff --git a/5.7/docker-entrypoint.sh b/5.7/docker-entrypoint.sh index b298781ec..3201cc9e7 100755 --- a/5.7/docker-entrypoint.sh +++ b/5.7/docker-entrypoint.sh @@ -23,7 +23,7 @@ _check_config() { if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then cat >&2 <<-EOM - ERROR: mysqld failed while attempting to determine datadir + ERROR: mysqld failed while attempting to check config command was: "${toRun[*]}" $errors