diff options
| author | Sam Yaple <sam@yaple.net> | 2015-06-25 14:33:28 +0000 |
|---|---|---|
| committer | Sam Yaple <sam@yaple.net> | 2015-07-03 13:56:06 +0000 |
| commit | efbfd7912b5fff41a3d3060af9e64c35c7e89f3b (patch) | |
| tree | f8b01517282cc2314d5ec2765d0a2e7643f7ff48 /docker/common | |
| parent | 90d92347e83e348ef5e2f1ed2faba2a3820ab436 (diff) | |
| download | kolla-efbfd7912b5fff41a3d3060af9e64c35c7e89f3b.tar.gz kolla-efbfd7912b5fff41a3d3060af9e64c35c7e89f3b.zip | |
Ansible Mariadb w/ Galera support
Adds initial support for Mariadb with Galera replication in Ansible
using the CONFIG_EXTERNAL methods.
Additionally, this refactors some of the Galera config script to allow
for reuse by CONFIG_EXTERNAL.
Partially Implements: blueprint ansible-service
Change-Id: I566fea0376ecca39fc8a5167f9ff9ff434ea7b7e
Diffstat (limited to 'docker/common')
| -rw-r--r-- | docker/common/base/kolla-common.sh | 10 | ||||
| -rw-r--r-- | docker/common/galera/config-external.sh | 8 | ||||
| -rwxr-xr-x | docker/common/galera/config-galera.sh | 20 | ||||
| -rwxr-xr-x | docker/common/galera/config-internal.sh | 20 | ||||
| -rwxr-xr-x | docker/common/galera/start.sh | 26 |
5 files changed, 59 insertions, 25 deletions
diff --git a/docker/common/base/kolla-common.sh b/docker/common/base/kolla-common.sh index bd6a539a0..5c07b375d 100644 --- a/docker/common/base/kolla-common.sh +++ b/docker/common/base/kolla-common.sh @@ -175,19 +175,19 @@ set_configs() { exec /opt/kolla/config-internal.sh ;; CONFIG_EXTERNAL_COPY_ALWAYS) - source /opt/kolla/config-exernal.sh + source /opt/kolla/config-external.sh ;; CONFIG_EXTERNAL_COPY_ONCE) if [[ -f /configured ]]; then echo 'INFO - This container has already been configured; Refusing to copy new configs' - return + else + source /opt/kolla/config-external.sh + touch /configured fi - source /opt/kolla/config-exernal.sh - touch /configured ;; *) - echo '$CONFIG_STRATEGY is not set properly' + echo '$KOLLA_CONFIG_STRATEGY is not set properly' exit 1 ;; esac diff --git a/docker/common/galera/config-external.sh b/docker/common/galera/config-external.sh new file mode 100644 index 000000000..a90f7fe6f --- /dev/null +++ b/docker/common/galera/config-external.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Cluster configuration +if [[ -f /opt/kolla/mariadb/galera.cnf ]]; then + cp /opt/kolla/mariadb/galera.cnf /etc/my.cnf.d/galera.cnf + chown mysql: /etc/my.cnf.d/galera.cnf + chmod 0600 /etc/my.cnf.d/galera.cnf +fi diff --git a/docker/common/galera/config-galera.sh b/docker/common/galera/config-galera.sh index 9cbd2c764..8aab3cfe1 100755 --- a/docker/common/galera/config-galera.sh +++ b/docker/common/galera/config-galera.sh @@ -1,13 +1,5 @@ #!/bin/bash -. /opt/kolla/kolla-common.sh - -check_required_vars DB_CLUSTER_BIND_ADDRESS DB_CLUSTER_NAME DB_CLUSTER_NODES \ - DB_ROOT_PASSWORD DB_CLUSTER_WSREP_METHOD - -CFG=/etc/my.cnf.d/server.cnf -DB_CLUSTER_INIT_SQL=/tmp/mysql-first-time.sql - function configure_files { crudini --set $CFG mariadb bind-address "${DB_CLUSTER_BIND_ADDRESS}" crudini --set $CFG mariadb binlog_format "ROW" @@ -30,8 +22,9 @@ function configure_files { crudini --set $CFG mariadb wsrep_sst_method "${DB_CLUSTER_WSREP_METHOD}" } -function bootstrap_database { - mysqld_safe & +function bootstrap_db { + mysqld_safe --wsrep-new-cluster & + # Waiting for deamon sleep 10 expect -c ' @@ -54,11 +47,14 @@ function bootstrap_database { expect "Reload privilege tables now?" send "y\r" expect eof' + + mysql -u root --password="${DB_ROOT_PASSWORD}" -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '${DB_ROOT_PASSWORD}' WITH GRANT OPTION;" + mysql -u root --password="${DB_ROOT_PASSWORD}" -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '${DB_ROOT_PASSWORD}' WITH GRANT OPTION;" mysqladmin -p"${DB_ROOT_PASSWORD}" shutdown } function configure_db { - bootstrap_database + bootstrap_db echo "GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '$DB_ROOT_PASSWORD' ;" > $DB_CLUSTER_INIT_SQL @@ -81,7 +77,7 @@ function populate_db { if [[ $(ls /var/lib/mysql) == "" ]]; then echo "POPULATING NEW DB" mysql_install_db - chown -R mysql /var/lib/mysql + chown -R mysql: /var/lib/mysql else echo "DB ALREADY EXISTS" fi diff --git a/docker/common/galera/config-internal.sh b/docker/common/galera/config-internal.sh new file mode 100755 index 000000000..5e55dcde4 --- /dev/null +++ b/docker/common/galera/config-internal.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +. /opt/kolla/kolla-common.sh +. /opt/kolla/config-galera.sh + +check_required_vars DB_CLUSTER_BIND_ADDRESS DB_CLUSTER_NAME DB_CLUSTER_NODES \ + DB_ROOT_PASSWORD DB_CLUSTER_WSREP_METHOD DB_CLUSTER_INIT_DB + +CFG=/etc/my.cnf.d/server.cnf +DB_CLUSTER_INIT_SQL=/tmp/mysql-first-time.sql + +prepare_db + +if [[ "${DB_CLUSTER_INIT_DB}" == "true" ]] && ! [[ -a /var/lib/mysql/cluster.exists ]]; then + DB_CLUSTER_IS_MASTER_NODE="--wsrep-new-cluster" + touch /var/lib/mysql/cluster.exists +fi + +mysqld_safe --init-file=$DB_CLUSTER_INIT_SQL $DB_CLUSTER_IS_MASTER_NODE + diff --git a/docker/common/galera/start.sh b/docker/common/galera/start.sh index 2ac683f11..42bd882b1 100755 --- a/docker/common/galera/start.sh +++ b/docker/common/galera/start.sh @@ -1,15 +1,25 @@ #!/bin/bash -. /opt/kolla/kolla-common.sh -. /opt/kolla/config-galera.sh +set -o errexit -check_required_vars DB_CLUSTER_INIT_DB -prepare_db +CMD="/usr/bin/mysqld_safe" +ARGS="" -if [[ "${DB_CLUSTER_INIT_DB}" == "true" ]] && ! [[ -a /var/lib/mysql/cluster.exists ]]; then - DB_CLUSTER_IS_MASTER_NODE="--wsrep-new-cluster" +# loading common functions +source /opt/kolla/kolla-common.sh + +# config-internal script exec out of this function, it does not return here +set_configs + +# loading functions +source /opt/kolla/config/config-galera.sh + +# This catches all cases of the BOOTSTRAP variable being set, including empty +if [[ "${!KOLLA_BOOTSTRAP[@]}" ]] && [[ ! -e /var/lib/mysql/cluster.exists ]]; then + ARGS="--wsrep-new-cluster" touch /var/lib/mysql/cluster.exists + populate_db + bootstrap_db fi -mysqld_safe --init-file=$DB_CLUSTER_INIT_SQL $DB_CLUSTER_IS_MASTER_NODE - +exec $CMD $ARGS |
