Skip to content

Commit 57bfe39

Browse files
committed
Update a few minor bits for consistency and proper failure
1. whitespace 2. replace `&&` with `;` to ensure `set -e` Does The Right Thing 3. add a warning for 5.5 + `MYSQL_ONETIME_PASSWORD` (`PASSWORD EXPIRE` unsupported) ```diff diff --git a/5.7/docker-entrypoint.sh b/5.6/docker-entrypoint.sh index 025638a..77feab0 100755 --- a/5.7/docker-entrypoint.sh +++ b/5.6/docker-entrypoint.sh @@ -21,7 +21,7 @@ if [ "$1" = 'mysqld' ]; then chown -R mysql:mysql "$DATADIR" echo 'Initializing database' - "$@" --initialize-insecure + mysql_install_db --user=mysql --datadir="$DATADIR" --rpm --keep-my-cnf echo 'Database initialized' "$@" --skip-networking & ``` ```diff diff --git a/5.6/docker-entrypoint.sh b/5.5/docker-entrypoint.sh index 77feab0..1313cd5 100755 --- a/5.6/docker-entrypoint.sh +++ b/5.5/docker-entrypoint.sh @@ -21,10 +21,10 @@ if [ "$1" = 'mysqld' ]; then chown -R mysql:mysql "$DATADIR" echo 'Initializing database' - mysql_install_db --user=mysql --datadir="$DATADIR" --rpm --keep-my-cnf + mysql_install_db --user=mysql --datadir="$DATADIR" --rpm --basedir=/usr/local/mysql echo 'Database initialized' - "$@" --skip-networking & + "$@" --skip-networking --basedir=/usr/local/mysql & pid="$!" mysql=( mysql --protocol=socket -uroot ) @@ -93,9 +93,9 @@ if [ "$1" = 'mysqld' ]; then done if [ ! -z "$MYSQL_ONETIME_PASSWORD" ]; then - "${mysql[@]}" <<-EOSQL - ALTER USER 'root'@'%' PASSWORD EXPIRE; - EOSQL + echo >&2 + echo >&2 Sorry, this version of MySQL does not support "PASSWORD EXPIRE" (required for MYSQL_ONETIME_PASSWORD). + echo >&2 fi if ! kill -s TERM "$pid" || ! wait "$pid"; then echo >&2 'MySQL init process failed.' ```
1 parent 2e80e5f commit 57bfe39

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

5.5/docker-entrypoint.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -e
2+
set -eo pipefail
33

44
# if command starts with an option, prepend mysqld
55
if [ "${1:0:1}" = '-' ]; then
@@ -16,6 +16,7 @@ if [ "$1" = 'mysqld' ]; then
1616
echo >&2 ' You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD'
1717
exit 1
1818
fi
19+
1920
mkdir -p "$DATADIR"
2021
chown -R mysql:mysql "$DATADIR"
2122

@@ -84,13 +85,18 @@ if [ "$1" = 'mysqld' ]; then
8485
for f in /docker-entrypoint-initdb.d/*; do
8586
case "$f" in
8687
*.sh) echo "$0: running $f"; . "$f" ;;
87-
*.sql) echo "$0: running $f"; "${mysql[@]}" < "$f" && echo ;;
88-
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}" && echo ;;
88+
*.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;;
89+
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;;
8990
*) echo "$0: ignoring $f" ;;
9091
esac
9192
echo
9293
done
9394

95+
if [ ! -z "$MYSQL_ONETIME_PASSWORD" ]; then
96+
echo >&2
97+
echo >&2 Sorry, this version of MySQL does not support "PASSWORD EXPIRE" (required for MYSQL_ONETIME_PASSWORD).
98+
echo >&2
99+
fi
94100
if ! kill -s TERM "$pid" || ! wait "$pid"; then
95101
echo >&2 'MySQL init process failed.'
96102
exit 1

5.6/docker-entrypoint.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -e
2+
set -eo pipefail
33

44
# if command starts with an option, prepend mysqld
55
if [ "${1:0:1}" = '-' ]; then
@@ -16,6 +16,7 @@ if [ "$1" = 'mysqld' ]; then
1616
echo >&2 ' You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD'
1717
exit 1
1818
fi
19+
1920
mkdir -p "$DATADIR"
2021
chown -R mysql:mysql "$DATADIR"
2122

@@ -84,8 +85,8 @@ if [ "$1" = 'mysqld' ]; then
8485
for f in /docker-entrypoint-initdb.d/*; do
8586
case "$f" in
8687
*.sh) echo "$0: running $f"; . "$f" ;;
87-
*.sql) echo "$0: running $f"; "${mysql[@]}" < "$f" && echo ;;
88-
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}" && echo ;;
88+
*.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;;
89+
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;;
8990
*) echo "$0: ignoring $f" ;;
9091
esac
9192
echo

5.7/docker-entrypoint.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -e
2+
set -eo pipefail
33

44
# if command starts with an option, prepend mysqld
55
if [ "${1:0:1}" = '-' ]; then
@@ -21,7 +21,7 @@ if [ "$1" = 'mysqld' ]; then
2121
chown -R mysql:mysql "$DATADIR"
2222

2323
echo 'Initializing database'
24-
mysqld --initialize-insecure=on --datadir="$DATADIR"
24+
"$@" --initialize-insecure
2525
echo 'Database initialized'
2626

2727
"$@" --skip-networking &
@@ -46,7 +46,6 @@ if [ "$1" = 'mysqld' ]; then
4646
mysql_tzinfo_to_sql /usr/share/zoneinfo | sed 's/Local time zone must be set--see zic manual page/FCTY/' | "${mysql[@]}" mysql
4747
fi
4848

49-
5049
if [ ! -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
5150
MYSQL_ROOT_PASSWORD="$(pwgen -1 32)"
5251
echo "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD"
@@ -81,12 +80,13 @@ if [ "$1" = 'mysqld' ]; then
8180

8281
echo 'FLUSH PRIVILEGES ;' | "${mysql[@]}"
8382
fi
83+
8484
echo
8585
for f in /docker-entrypoint-initdb.d/*; do
8686
case "$f" in
8787
*.sh) echo "$0: running $f"; . "$f" ;;
88-
*.sql) echo "$0: running $f"; "${mysql[@]}" < "$f" && echo ;;
89-
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}" && echo ;;
88+
*.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;;
89+
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;;
9090
*) echo "$0: ignoring $f" ;;
9191
esac
9292
echo

0 commit comments

Comments
 (0)