From ed198ce2e8aa78613c615f20c5c4dd09fa450f66 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Wed, 20 Jan 2016 15:02:21 -0800 Subject: [PATCH] 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) --- 5.5/docker-entrypoint.sh | 12 +++++++++--- 5.6/docker-entrypoint.sh | 7 ++++--- 5.7/docker-entrypoint.sh | 10 +++++----- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/5.5/docker-entrypoint.sh b/5.5/docker-entrypoint.sh index 02a866c28..1eb483e5f 100755 --- a/5.5/docker-entrypoint.sh +++ b/5.5/docker-entrypoint.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -eo pipefail # if command starts with an option, prepend mysqld if [ "${1:0:1}" = '-' ]; then @@ -16,6 +16,7 @@ if [ "$1" = 'mysqld' ]; then echo >&2 ' You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD' exit 1 fi + mkdir -p "$DATADIR" chown -R mysql:mysql "$DATADIR" @@ -84,13 +85,18 @@ if [ "$1" = 'mysqld' ]; then for f in /docker-entrypoint-initdb.d/*; do case "$f" in *.sh) echo "$0: running $f"; . "$f" ;; - *.sql) echo "$0: running $f"; "${mysql[@]}" < "$f" && echo ;; - *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}" && echo ;; + *.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;; + *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;; *) echo "$0: ignoring $f" ;; esac echo done + if [ ! -z "$MYSQL_ONETIME_PASSWORD" ]; then + 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.' exit 1 diff --git a/5.6/docker-entrypoint.sh b/5.6/docker-entrypoint.sh index 8ad2f70a1..77feab06c 100755 --- a/5.6/docker-entrypoint.sh +++ b/5.6/docker-entrypoint.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -eo pipefail # if command starts with an option, prepend mysqld if [ "${1:0:1}" = '-' ]; then @@ -16,6 +16,7 @@ if [ "$1" = 'mysqld' ]; then echo >&2 ' You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD' exit 1 fi + mkdir -p "$DATADIR" chown -R mysql:mysql "$DATADIR" @@ -84,8 +85,8 @@ if [ "$1" = 'mysqld' ]; then for f in /docker-entrypoint-initdb.d/*; do case "$f" in *.sh) echo "$0: running $f"; . "$f" ;; - *.sql) echo "$0: running $f"; "${mysql[@]}" < "$f" && echo ;; - *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}" && echo ;; + *.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;; + *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;; *) echo "$0: ignoring $f" ;; esac echo diff --git a/5.7/docker-entrypoint.sh b/5.7/docker-entrypoint.sh index e9b66e105..025638a90 100755 --- a/5.7/docker-entrypoint.sh +++ b/5.7/docker-entrypoint.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -eo pipefail # if command starts with an option, prepend mysqld if [ "${1:0:1}" = '-' ]; then @@ -21,7 +21,7 @@ if [ "$1" = 'mysqld' ]; then chown -R mysql:mysql "$DATADIR" echo 'Initializing database' - mysqld --initialize-insecure=on --datadir="$DATADIR" + "$@" --initialize-insecure echo 'Database initialized' "$@" --skip-networking & @@ -46,7 +46,6 @@ if [ "$1" = 'mysqld' ]; then mysql_tzinfo_to_sql /usr/share/zoneinfo | sed 's/Local time zone must be set--see zic manual page/FCTY/' | "${mysql[@]}" mysql fi - if [ ! -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then MYSQL_ROOT_PASSWORD="$(pwgen -1 32)" echo "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD" @@ -81,12 +80,13 @@ if [ "$1" = 'mysqld' ]; then echo 'FLUSH PRIVILEGES ;' | "${mysql[@]}" fi + echo for f in /docker-entrypoint-initdb.d/*; do case "$f" in *.sh) echo "$0: running $f"; . "$f" ;; - *.sql) echo "$0: running $f"; "${mysql[@]}" < "$f" && echo ;; - *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}" && echo ;; + *.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;; + *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;; *) echo "$0: ignoring $f" ;; esac echo