From 9d505bb93429729bcc94439cfd47fddc830ff671 Mon Sep 17 00:00:00 2001 From: Joe Ferguson Date: Fri, 30 Sep 2016 14:14:20 -0700 Subject: [PATCH] catch config errors before scraping datadir from help output - also, sync `nullglob` from mysql entrypoint --- 10.0/docker-entrypoint.sh | 20 +++++++++++++++++++- 10.1/docker-entrypoint.sh | 20 +++++++++++++++++++- 5.5/docker-entrypoint.sh | 20 +++++++++++++++++++- docker-entrypoint.sh | 20 +++++++++++++++++++- 4 files changed, 76 insertions(+), 4 deletions(-) diff --git a/10.0/docker-entrypoint.sh b/10.0/docker-entrypoint.sh index ea896b99..576e2a53 100755 --- a/10.0/docker-entrypoint.sh +++ b/10.0/docker-entrypoint.sh @@ -1,5 +1,6 @@ #!/bin/bash set -eo pipefail +shopt -s nullglob # if command starts with an option, prepend mysqld if [ "${1:0:1}" = '-' ]; then @@ -17,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 check config + 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" @@ -30,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/10.1/docker-entrypoint.sh b/10.1/docker-entrypoint.sh index ea896b99..576e2a53 100755 --- a/10.1/docker-entrypoint.sh +++ b/10.1/docker-entrypoint.sh @@ -1,5 +1,6 @@ #!/bin/bash set -eo pipefail +shopt -s nullglob # if command starts with an option, prepend mysqld if [ "${1:0:1}" = '-' ]; then @@ -17,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 check config + 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" @@ -30,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.5/docker-entrypoint.sh b/5.5/docker-entrypoint.sh index ea896b99..576e2a53 100755 --- a/5.5/docker-entrypoint.sh +++ b/5.5/docker-entrypoint.sh @@ -1,5 +1,6 @@ #!/bin/bash set -eo pipefail +shopt -s nullglob # if command starts with an option, prepend mysqld if [ "${1:0:1}" = '-' ]; then @@ -17,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 check config + 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" @@ -30,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/docker-entrypoint.sh b/docker-entrypoint.sh index ea896b99..576e2a53 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,5 +1,6 @@ #!/bin/bash set -eo pipefail +shopt -s nullglob # if command starts with an option, prepend mysqld if [ "${1:0:1}" = '-' ]; then @@ -17,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 check config + 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" @@ -30,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 "$@")"