From b1f73641c831d7cecbc0fb69d38dc4185afaea9f Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Fri, 27 Nov 2020 02:37:48 -0700 Subject: [PATCH] catch errors and terminate script --- .vscode/numbered-bookmarks.json | 18 +++++++++++++++++- entrypoint.sh | 18 +++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.vscode/numbered-bookmarks.json b/.vscode/numbered-bookmarks.json index 4c08963..e5ae6fb 100644 --- a/.vscode/numbered-bookmarks.json +++ b/.vscode/numbered-bookmarks.json @@ -1,3 +1,19 @@ { - "bookmarks": [] + "bookmarks": [ + { + "fsPath": "$ROOTPATH$/entrypoint.sh", + "bookmarks": [ + -1, + 72, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1 + ] + } + ] } \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index b4c993a..27e44ce 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -21,7 +21,9 @@ chown -R mysql:mysql /var/lib/mysql for f in /docker-entrypoint-preinit.d/*.sh; do if [ -s "$f" ]; then printf "PRE-INIT: Executing %s\n" "$f" - /bin/sh "$f" + if (! /bin/sh "$f"); then + exit 2 + fi fi done @@ -81,19 +83,23 @@ for f in /docker-entrypoint-initdb.d/*.sh; do *.sql) if [ -s "$f" ]; then printf "IMPORT-SQL: Importing %s\n" "$f" - mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f" + if (! mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f"); then + exit 3 + fi printf "\n" fi ;; *.sql.gz) if [ -s "$f" ]; then printf "IMPORT-SQL: Importing %s\n" "$f" - gunzip -c "$f" | mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 + if (! gunzip -c "$f" | mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0); then + exit 3 + fi printf "\n" fi ;; *) - printf "IMPORT-SQL: Cannot import %s\n" "$f" + printf "IMPORT-SQL: Cannot import %s -- skipping\n" "$f" ;; esac done @@ -102,7 +108,9 @@ done for f in /docker-entrypoint-postinit.d/*.sh; do if [ -s "$f" ]; then printf "POST-INIT: Executing %s\n" "$f" - /bin/sh "$f" + if (! /bin/sh "$f"); then + exit 4 + fi fi done