From 09fdc30784292bdf7b3637eb3723522a0ed47f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Mon, 11 Feb 2019 09:28:44 +0100 Subject: [PATCH] Fix mysql connection errror on boot Mysql triggers "Host 'xxx' is not allowed to connect to this MySQL server" error because of race condition. This was an issue that had been (painfully) solved in v2 and has reared its ugly head again in v3. Close #159 Close #160 --- CHANGELOG.md | 1 + tutor/local.py | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71135cd..0433e76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Latest +- [Bugfix] fix mysql initialization (#156, #160) - [Improvement] Better handling of continuous integration - [Bugfix] fix `tutor --version` (#156) - [Improvement] Absolute settings imports -- 📯 thanks @tonytan4ever! diff --git a/tutor/local.py b/tutor/local.py index b294216..81e594a 100644 --- a/tutor/local.py +++ b/tutor/local.py @@ -1,4 +1,5 @@ import os +import subprocess from time import sleep import click @@ -130,17 +131,27 @@ def run(root, service, command, args): ) @opts.root def databases(root): - mysql_data_path = tutor_env.data_path(root, "mysql", "mysql") - if not os.path.exists(mysql_data_path): - click.echo(fmt.info("Initializing MySQL database...")) - docker_compose(root, "up", "-d", "mysql") - while not os.path.exists(mysql_data_path): - click.echo(fmt.info(" waiting for creation of {}".format(mysql_data_path))) - sleep(4) - click.echo(fmt.info("MySQL database initialized")) - docker_compose(root, "stop", "mysql") + init_mysql(root) ops.migrate(root, run_bash) +def init_mysql(root): + mysql_data_path = tutor_env.data_path(root, "mysql", "mysql") + if os.path.exists(mysql_data_path): + return + click.echo(fmt.info("Initializing MySQL database...")) + docker_compose(root, "up", "-d", "mysql") + while True: + click.echo(fmt.info(" waiting for mysql initialization")) + logs = subprocess.check_output([ + "docker-compose", "-f", tutor_env.pathjoin(root, "local", "docker-compose.yml"), + "logs", "mysql", + ]) + if b"MySQL init process done. Ready for start up." in logs: + click.echo(fmt.info("MySQL database initialized")) + docker_compose(root, "stop", "mysql") + return + sleep(4) + @click.group(help="Manage https certificates") def https(): pass