From 3831e2e53dfb99dff982148eb25da0c268467bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Mon, 1 Jun 2020 17:11:10 +0200 Subject: [PATCH] Make the mysql root username a configuration parameter This allows users who connect to an external database to customise the root username. Indeed, quite often the "root" username is reserved. Close #328 --- CHANGELOG.md | 4 ++++ docs/configuration.rst | 2 ++ tutor/templates/config.yml | 1 + tutor/templates/hooks/mysql/init | 6 +++--- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98e3389..c2ecffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ Note: Breaking changes between versions are indicated by "💥". +## Unreleased + +- [Improvement] Make it possible to customize the MySQL root username, for connecting to external MySQL databases + ## v3.12.5 (2020-05-20) - [Improvement] Upgrade Android app to v2.21.1 and enable many features, such as downloading videos to SD card. Thanks for the help @ejklock! diff --git a/docs/configuration.rst b/docs/configuration.rst index f5ce84e..4c399ca 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -104,12 +104,14 @@ MySQL - ``ACTIVATE_MYSQL`` (default: ``true``) - ``MYSQL_HOST`` (default: ``"mysql"``) - ``MYSQL_PORT`` (default: ``3306``) +- ``MYSQL_ROOT_USERNAME`` (default: ``"root"``) - ``MYSQL_ROOT_PASSWORD`` (default: randomly generated) Note that you are responsible for creating the root user if you are using a managed database. By default, a running Open edX platform deployed with Tutor includes all necessary 3rd-party services, such as MySQL, MongoDb, etc. But it's also possible to store data on a separate database, such as `Amazon RDS `_. For instance, to store data on an external MySQL database, set the following configuration:: ACTIVATE_MYSQL: false MYSQL_HOST: yourhost + MYSQL_ROOT_USERNAME: MYSQL_ROOT_PASSWORD: Elasticsearch diff --git a/tutor/templates/config.yml b/tutor/templates/config.yml index 632ff5c..55e2be8 100644 --- a/tutor/templates/config.yml +++ b/tutor/templates/config.yml @@ -64,6 +64,7 @@ OPENEDX_MYSQL_DATABASE: "openedx" OPENEDX_MYSQL_USERNAME: "openedx" MYSQL_HOST: "mysql" MYSQL_PORT: 3306 +MYSQL_ROOT_USERNAME: "root" NGINX_HTTP_PORT: 80 NGINX_HTTPS_PORT: 443 PLATFORM_NAME: "My Open edX" diff --git a/tutor/templates/hooks/mysql/init b/tutor/templates/hooks/mysql/init index 91d327f..432e559 100644 --- a/tutor/templates/hooks/mysql/init +++ b/tutor/templates/hooks/mysql/init @@ -1,7 +1,7 @@ echo "Initialising MySQL..." mysql_connection_max_attempts=10 mysql_connection_attempt=0 -until mysql -u root --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e 'exit' +until mysql -u {{ MYSQL_ROOT_USERNAME }} --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e 'exit' do mysql_connection_attempt=$(expr $mysql_connection_attempt + 1) echo " [$mysql_connection_attempt/$mysql_connection_max_attempts] Waiting for MySQL service (this may take a while)..." @@ -14,5 +14,5 @@ do done echo "MySQL is up and running" -mysql -u root --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e 'CREATE DATABASE IF NOT EXISTS {{ OPENEDX_MYSQL_DATABASE }};' -mysql -u root --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e 'GRANT ALL ON {{ OPENEDX_MYSQL_DATABASE }}.* TO "{{ OPENEDX_MYSQL_USERNAME }}"@"%" IDENTIFIED BY "{{ OPENEDX_MYSQL_PASSWORD }}";' \ No newline at end of file +mysql -u {{ MYSQL_ROOT_USERNAME }} --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e 'CREATE DATABASE IF NOT EXISTS {{ OPENEDX_MYSQL_DATABASE }};' +mysql -u {{ MYSQL_ROOT_USERNAME }} --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e 'GRANT ALL ON {{ OPENEDX_MYSQL_DATABASE }}.* TO "{{ OPENEDX_MYSQL_USERNAME }}"@"%" IDENTIFIED BY "{{ OPENEDX_MYSQL_PASSWORD }}";' \ No newline at end of file