From 30bc6df09197ab654bf088991c89d214a8446a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Sun, 16 Sep 2018 13:24:17 +0200 Subject: [PATCH] Improve wait for mysql db to be ready --- Makefile | 2 +- configurator/templates/openedx/oauth2.sh | 2 +- configurator/templates/openedx/provision.sh | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7c2b97e..dd5ae3c 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ update: migrate: provision-database migrate-openedx migrate-forum $(extra_migrate_targets) provision-oauth2 provision-database: - $(DOCKER_COMPOSE_RUN) lms bash -c "dockerize -wait tcp://mysql:3306 -timeout 20s && bash /openedx/config/provision.sh" + $(DOCKER_COMPOSE_RUN) lms /openedx/config/provision.sh provision-oauth2: $(DOCKER_COMPOSE_RUN) lms /openedx/config/oauth2.sh diff --git a/configurator/templates/openedx/oauth2.sh b/configurator/templates/openedx/oauth2.sh index 5e6aac3..ce9b05b 100755 --- a/configurator/templates/openedx/oauth2.sh +++ b/configurator/templates/openedx/oauth2.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e {% if ACTIVATE_NOTES %} ./manage.py lms manage_user notes notes@{{ LMS_HOST }} --staff --superuser diff --git a/configurator/templates/openedx/provision.sh b/configurator/templates/openedx/provision.sh index 41e5951..b540ca6 100755 --- a/configurator/templates/openedx/provision.sh +++ b/configurator/templates/openedx/provision.sh @@ -1,3 +1,11 @@ +#!/bin/bash -e +dockerize -wait tcp://mysql:3306 -timeout 20s + +while ! mysql -u root --password="{{ MYSQL_PASSWORD }}" --host "mysql" -e="\r"; do + echo "Waiting for mysql database to be ready..." + sleep 1 +done + mysql -u root --password="{{ MYSQL_PASSWORD }}" --host "mysql" -e 'CREATE DATABASE IF NOT EXISTS {{ MYSQL_DATABASE }};' mysql -u root --password="{{ MYSQL_PASSWORD }}" --host "mysql" -e 'GRANT ALL ON {{ MYSQL_DATABASE }}.* TO "{{ MYSQL_USERNAME }}"@"%" IDENTIFIED BY "{{ MYSQL_PASSWORD }}";'