Skip to content

Commit

Permalink
catch errors before scraping datadir from help output
Browse files Browse the repository at this point in the history
  • Loading branch information
yosifkit committed Oct 7, 2016
1 parent de740a4 commit a1fce0d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
19 changes: 18 additions & 1 deletion 5.5/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,36 @@ 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"
exec gosu mysql "$BASH_SOURCE" "$@"
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 "$@")"

Expand Down
19 changes: 18 additions & 1 deletion 5.6/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,36 @@ 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"
exec gosu mysql "$BASH_SOURCE" "$@"
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 "$@")"

Expand Down
17 changes: 17 additions & 0 deletions 5.7/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,36 @@ 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"
exec gosu mysql "$BASH_SOURCE" "$@"
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 "$@")"

Expand Down

0 comments on commit a1fce0d

Please sign in to comment.