Skip to content

Commit 0312071

Browse files
authored
Merge pull request #218 from infosiftr/fix-datadir-scrape
Catch errors when scraping datadir from help output
2 parents de740a4 + bdd76e5 commit 0312071

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

5.5/docker-entrypoint.sh

+18-1
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,36 @@ for arg; do
1818
esac
1919
done
2020

21+
_check_config() {
22+
toRun=( "$@" --verbose --help --log-bin-index="$(mktemp -u)" )
23+
if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then
24+
cat >&2 <<-EOM
25+
26+
ERROR: mysqld failed while attempting to check config
27+
command was: "${toRun[*]}"
28+
29+
$errors
30+
EOM
31+
exit 1
32+
fi
33+
}
34+
2135
_datadir() {
22-
"$@" --verbose --help --log-bin-index=`mktemp -u` 2>/dev/null | awk '$1 == "datadir" { print $2; exit }'
36+
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "datadir" { print $2; exit }'
2337
}
2438

2539
# allow the container to be started with `--user`
2640
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
41+
_check_config "$@"
2742
DATADIR="$(_datadir "$@")"
2843
mkdir -p "$DATADIR"
2944
chown -R mysql:mysql "$DATADIR"
3045
exec gosu mysql "$BASH_SOURCE" "$@"
3146
fi
3247

3348
if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
49+
# still need to check config, container may have started with --user
50+
_check_config "$@"
3451
# Get config
3552
DATADIR="$(_datadir "$@")"
3653

5.6/docker-entrypoint.sh

+18-1
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,36 @@ for arg; do
1818
esac
1919
done
2020

21+
_check_config() {
22+
toRun=( "$@" --verbose --help --log-bin-index="$(mktemp -u)" )
23+
if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then
24+
cat >&2 <<-EOM
25+
26+
ERROR: mysqld failed while attempting to check config
27+
command was: "${toRun[*]}"
28+
29+
$errors
30+
EOM
31+
exit 1
32+
fi
33+
}
34+
2135
_datadir() {
22-
"$@" --verbose --help --log-bin-index=`mktemp -u` 2>/dev/null | awk '$1 == "datadir" { print $2; exit }'
36+
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "datadir" { print $2; exit }'
2337
}
2438

2539
# allow the container to be started with `--user`
2640
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
41+
_check_config "$@"
2742
DATADIR="$(_datadir "$@")"
2843
mkdir -p "$DATADIR"
2944
chown -R mysql:mysql "$DATADIR"
3045
exec gosu mysql "$BASH_SOURCE" "$@"
3146
fi
3247

3348
if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
49+
# still need to check config, container may have started with --user
50+
_check_config "$@"
3451
# Get config
3552
DATADIR="$(_datadir "$@")"
3653

5.7/docker-entrypoint.sh

+17
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,36 @@ for arg; do
1818
esac
1919
done
2020

21+
_check_config() {
22+
toRun=( "$@" --verbose --help )
23+
if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then
24+
cat >&2 <<-EOM
25+
26+
ERROR: mysqld failed while attempting to check config
27+
command was: "${toRun[*]}"
28+
29+
$errors
30+
EOM
31+
exit 1
32+
fi
33+
}
34+
2135
_datadir() {
2236
"$@" --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }'
2337
}
2438

2539
# allow the container to be started with `--user`
2640
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
41+
_check_config "$@"
2742
DATADIR="$(_datadir "$@")"
2843
mkdir -p "$DATADIR"
2944
chown -R mysql:mysql "$DATADIR"
3045
exec gosu mysql "$BASH_SOURCE" "$@"
3146
fi
3247

3348
if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
49+
# still need to check config, container may have started with --user
50+
_check_config "$@"
3451
# Get config
3552
DATADIR="$(_datadir "$@")"
3653

0 commit comments

Comments
 (0)