From 7e2ce014316677af9b83c42745afe9e42f0c8709 Mon Sep 17 00:00:00 2001 From: SamYaple Date: Mon, 25 Jan 2016 16:04:26 +0000 Subject: [PATCH] Cleanup mariadb and make compatiable with mesos There is no reason to have a hostname-unique pidfile in the container as we currently have. This posed problems with kolla-mesos reusing the same script. Since there is no reason for this pidfile to be configurable in path _at_ _all_, we hardcode the path. Additionally, we adjust the file perm change to only update the perms on the folder if it is not already properly set. This also incorperates a kolla-ansible file in the bootstrap process which follows our other container techniques of using the idempotent creation of a volume in the bootstrap process (see nova) TrivialFix Related-Bug: #1538136 Change-Id: I2380529fc7146a9603145cdc31e649cb8841f7dd --- ansible/roles/mariadb/tasks/bootstrap.yml | 29 ++++++++++--------- ansible/roles/mariadb/tasks/start.yml | 2 +- ansible/roles/mariadb/templates/galera.cnf.j2 | 2 +- docker/mariadb/extend_start.sh | 7 +++-- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/ansible/roles/mariadb/tasks/bootstrap.yml b/ansible/roles/mariadb/tasks/bootstrap.yml index af7d8f3084..ac8254a35b 100644 --- a/ansible/roles/mariadb/tasks/bootstrap.yml +++ b/ansible/roles/mariadb/tasks/bootstrap.yml @@ -11,20 +11,18 @@ always_run: True run_once: True -# TODO(SamYaple): Improve failed_when check -- name: Checking if a previous cluster exists - command: docker exec mariadb stat /var/lib/mysql/grastate.dat - register: exists - changed_when: False - failed_when: False - always_run: True - run_once: True +- name: Creating mariadb volume + kolla_docker: + action: "create_volume" + common_options: "{{ docker_common_options }}" + name: "mariadb" + register: mariadb_volume - name: Writing hostname of host with existing cluster files to temp file local_action: copy content={{ ansible_hostname }} dest=/tmp/kolla_mariadb_cluster mode=0600 changed_when: False always_run: True - when: exists.rc == 0 + when: not mariadb_volume | changed - name: Registering host from temp file set_fact: @@ -44,7 +42,6 @@ KOLLA_BOOTSTRAP: KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" DB_ROOT_PASSWORD: "{{ database_password }}" - DB_PID_FILE: "/var/lib/mysql/{{ hostvars[inventory_hostname]['ansible_hostname'] }}-galera.pid" DB_MAX_TIMEOUT: "{{ database_max_timeout }}" image: "{{ mariadb_image_full }}" name: "mariadb" @@ -52,13 +49,17 @@ volumes: - "{{ node_config_directory }}/mariadb/:{{ container_config_directory }}/:ro" - "mariadb:/var/lib/mysql" - when: delegate_host == 'None' and inventory_hostname == groups['mariadb'][0] + when: + - delegate_host == 'None' + - inventory_hostname == groups['mariadb'][0] - name: Waiting for MariaDB service to be ready - command: "docker exec mariadb ls /var/lib/mysql/{{ hostvars[inventory_hostname]['ansible_hostname'] }}-galera.pid /var/lib/mysql/cluster.exists" + command: "docker exec mariadb ls /var/lib/mysql/mariadb.pid" register: bootstrap_result - when: delegate_host == 'None' and inventory_hostname == groups['mariadb'][0] - until: bootstrap_result|success + when: + - delegate_host == 'None' + - inventory_hostname == groups['mariadb'][0] + until: bootstrap_result | success changed_when: False retries: 6 delay: 10 diff --git a/ansible/roles/mariadb/tasks/start.yml b/ansible/roles/mariadb/tasks/start.yml index cfc12c0631..8216b5eb8b 100644 --- a/ansible/roles/mariadb/tasks/start.yml +++ b/ansible/roles/mariadb/tasks/start.yml @@ -13,7 +13,7 @@ ( delegate_host == 'None' and inventory_hostname != groups['mariadb'][0] ) - name: Waiting for MariaDB service to be ready - command: "docker exec mariadb ls /var/lib/mysql/{{ hostvars[inventory_hostname]['ansible_hostname'] }}-galera.pid" + command: "docker exec mariadb ls /var/lib/mysql/mariadb.pid" register: bootstrap_result when: delegate_host != 'None' or ( groups['mariadb'] | length ) == 1 or diff --git a/ansible/roles/mariadb/templates/galera.cnf.j2 b/ansible/roles/mariadb/templates/galera.cnf.j2 index 4e1039268e..9f9ed3ecd8 100644 --- a/ansible/roles/mariadb/templates/galera.cnf.j2 +++ b/ansible/roles/mariadb/templates/galera.cnf.j2 @@ -26,4 +26,4 @@ wsrep_slave_threads=4 max_connections=1000 [server] -pid-file=/var/lib/mysql/{{ ansible_hostname }}-galera.pid +pid-file=/var/lib/mysql/mariadb.pid diff --git a/docker/mariadb/extend_start.sh b/docker/mariadb/extend_start.sh index dcbdac2edd..55e9ae4c90 100644 --- a/docker/mariadb/extend_start.sh +++ b/docker/mariadb/extend_start.sh @@ -4,7 +4,7 @@ function bootstrap_db { mysqld_safe --wsrep-new-cluster & # Wait for the mariadb server to be "Ready" before starting the security reset with a max timeout TIMEOUT=${DB_MAX_TIMEOUT:-60} - while [ ! -f ${DB_PID_FILE} ]; do + while [[ ! -f /var/lib/mysql/mariadb.pid ]]; do if [[ ${TIMEOUT} -gt 0 ]]; then let TIMEOUT-=1 sleep 1 @@ -18,7 +18,10 @@ function bootstrap_db { mysqladmin -uroot -p"${DB_ROOT_PASSWORD}" shutdown } -sudo chown mysql: /var/lib/mysql +# Only update permissions if permissions need to be updated +if [[ $(stat -c %U:%G /var/lib/mysql) != "mysql:mysql" ]]; then + sudo chown mysql: /var/lib/mysql +fi # This catches all cases of the BOOTSTRAP variable being set, including empty if [[ "${!KOLLA_BOOTSTRAP[@]}" ]] && [[ ! -e /var/lib/mysql/cluster.exists ]]; then