From 6361b9ad58f2a792f21395b9856af463c40b8e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Sat, 10 Feb 2018 18:38:17 +0100 Subject: [PATCH] Fix SQL race condition When running "wait-for-mysql.sh", the "echo 'show tables' | manage.py dbshell" command is always considered a success, even if the database is unreachable ($? == 0). So we replace this command by a global system check. This closes #3. --- Makefile | 4 ++-- edxapp/Dockerfile | 2 +- edxapp/wait-for-greenlight.sh | 10 ++++++++++ edxapp/wait-for-mysql.sh | 10 ---------- 4 files changed, 13 insertions(+), 13 deletions(-) create mode 100755 edxapp/wait-for-greenlight.sh delete mode 100755 edxapp/wait-for-mysql.sh diff --git a/Makefile b/Makefile index 56ae857..d012dec 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,8 @@ build: docker-compose build migrate: - docker-compose run --rm lms bash -c "./wait-for-mysql.sh && ./manage.py lms --settings=production migrate" - docker-compose run --rm cms bash -c "./wait-for-mysql.sh && ./manage.py cms --settings=production migrate" + docker-compose run --rm lms bash -c "./wait-for-greenlight.sh && ./manage.py lms --settings=production migrate" + docker-compose run --rm cms bash -c "./wait-for-greenlight.sh && ./manage.py cms --settings=production migrate" assets: docker-compose run --rm lms paver update_assets lms --settings=production diff --git a/edxapp/Dockerfile b/edxapp/Dockerfile index fef5c17..1d2c3dd 100644 --- a/edxapp/Dockerfile +++ b/edxapp/Dockerfile @@ -47,7 +47,7 @@ COPY ./config/lms.auth.json /openedx/ COPY ./config/cms.auth.json /openedx/ # Copy convenient script -COPY ./wait-for-mysql.sh . +COPY ./wait-for-greenlight.sh . ############ End of code common to lms & cms diff --git a/edxapp/wait-for-greenlight.sh b/edxapp/wait-for-greenlight.sh new file mode 100755 index 0000000..9eda518 --- /dev/null +++ b/edxapp/wait-for-greenlight.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +echo "Checking system..." +until ./manage.py lms --settings=production check +do + printf "." + sleep 1 +done + +echo -e "\nSystem is ready \\o/" diff --git a/edxapp/wait-for-mysql.sh b/edxapp/wait-for-mysql.sh deleted file mode 100755 index 344ce24..0000000 --- a/edxapp/wait-for-mysql.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -echo "Waiting for mysql database" -until echo "show tables;" | ./manage.py lms --settings=production dbshell -do - printf "." - sleep 1 -done - -echo -e "\nmysql database ready"