Skip to content

Commit 05833af

Browse files
Trond Humborstadltangvald
authored andcommitted
Add an early check for whether server can start, to detect config errors and notify user.
1 parent 27438b0 commit 05833af

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

5.5/docker-entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ if [ "${1:0:1}" = '-' ]; then
77
fi
88

99
if [ "$1" = 'mysqld' ]; then
10+
# Test we're able to startup without errors. We redirect stdout to /dev/null so
11+
# only the error messages are left.
12+
result=0
13+
output=$("$@" --verbose --help 2>&1 > /dev/null) || result=$?
14+
if [ ! "$result" = "0" ]; then
15+
echo >&2 'error: could not run mysql. This could be caused by a misconfigured my.cnf'
16+
echo >&2 "$output"
17+
exit 1
18+
fi
19+
1020
# Get config
1121
DATADIR="$("$@" --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }')"
1222

5.6/docker-entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ if [ "${1:0:1}" = '-' ]; then
77
fi
88

99
if [ "$1" = 'mysqld' ]; then
10+
# Test we're able to startup without errors. We redirect stdout to /dev/null so
11+
# only the error messages are left.
12+
result=0
13+
output=$("$@" --verbose --help 2>&1 > /dev/null) || result=$?
14+
if [ ! "$result" = "0" ]; then
15+
echo >&2 'error: could not run mysql. This could be caused by a misconfigured my.cnf'
16+
echo >&2 "$output"
17+
exit 1
18+
fi
19+
1020
# Get config
1121
DATADIR="$("$@" --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }')"
1222

5.7/docker-entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ if [ "${1:0:1}" = '-' ]; then
77
fi
88

99
if [ "$1" = 'mysqld' ]; then
10+
# Test we're able to startup without errors. We redirect stdout to /dev/null so
11+
# only the error messages are left.
12+
result=0
13+
output=$("$@" --verbose --help 2>&1 > /dev/null) || result=$?
14+
if [ ! "$result" = "0" ]; then
15+
echo >&2 'error: could not run mysql. This could be caused by a misconfigured my.cnf'
16+
echo >&2 "$output"
17+
exit 1
18+
fi
19+
1020
# Get config
1121
DATADIR="$("$@" --verbose --help --log-bin-index=/tmp/tmp.index 2>/dev/null | awk '$1 == "datadir" { print $2; exit }')"
1222

0 commit comments

Comments
 (0)