From ccf108ed2470c7b51f4e86224905815e4c4538a8 Mon Sep 17 00:00:00 2001 From: Matthew Thode Date: Sun, 27 Jan 2019 00:29:04 -0600 Subject: [PATCH] Add gentoo support to galera_server Depends-On: https://review.openstack.org/633289 Change-Id: I1ba3630e3f673aab419ebaff966f88868560df3b --- handlers/main.yml | 4 +- tasks/galera_install_portage.yml | 39 +++++++++++++ tasks/galera_post_install.yml | 18 +++++- tasks/galera_setup.yml | 2 +- .../galera_new_cluster.j2 | 6 +- templates/galera_secure_node.j2 | 8 +-- templates/my.cnf.j2 | 1 + vars/gentoo.yml | 58 +++++++++++++++++++ vars/main.yml | 1 + 9 files changed, 125 insertions(+), 12 deletions(-) create mode 100644 tasks/galera_install_portage.yml rename files/galera_new_cluster => templates/galera_new_cluster.j2 (92%) create mode 100644 vars/gentoo.yml create mode 100644 vars/main.yml diff --git a/handlers/main.yml b/handlers/main.yml index a35446be..89586074 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -16,7 +16,7 @@ - name: Reload the systemd daemon systemd: daemon_reload: yes - name: mysql + name: "{{ mysql_service_name }}" enabled: "yes" - name: Check node status @@ -70,7 +70,7 @@ - name: Restart mysql (All) service: - name: mysql + name: "{{ mysql_service_name }}" state: "{{ (not hostvars[item]['galera_cluster_ready'] | bool) | ternary('started', 'restarted') }}" environment: MYSQLD_STARTUP_TIMEOUT: 180 diff --git a/tasks/galera_install_portage.yml b/tasks/galera_install_portage.yml new file mode 100644 index 00000000..a1bcefa0 --- /dev/null +++ b/tasks/galera_install_portage.yml @@ -0,0 +1,39 @@ +--- +# Copyright 2019, Matthew Thode +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Install galera_server role packages + package: + name: "{{ galera_packages_list }}" + state: "{{ galera_server_package_state }}" + newuse: "{{ (ansible_pkg_mgr == 'portage') | ternary('yes', omit) }}" + changed_use: "{{ (ansible_pkg_mgr == 'portage') | ternary('yes', omit) }}" + noreplace: "{{ (ansible_pkg_mgr == 'portage') | ternary('yes', omit) }}" + jobs: "{{ (ansible_pkg_mgr == 'portage') | ternary('4', omit) }}" + register: install_remote_packages + until: install_remote_packages is success + retries: 5 + delay: 2 + +- name: Ensure mysql config directories exists + file: + src: "{{ item.src | default(omit) }}" + path: "{{ item.path }}" + state: "{{ item.state }}" + force: "{{ item.force | default(omit) }}" + with_items: + - path: "/etc/mysql" + state: "directory" + - path: "{{ galera_etc_include_dir }}" + state: "directory" diff --git a/tasks/galera_post_install.yml b/tasks/galera_post_install.yml index 807f713b..4708cf74 100644 --- a/tasks/galera_post_install.yml +++ b/tasks/galera_post_install.yml @@ -46,6 +46,7 @@ # as all of these tasks will be run on Package install # and running them again will cause a conflict within # debian based deployments. +# NOTE(prometheanfire): Ditto Gentoo ^ - name: Create galera initial secure tool template: src: "galera_secure_node.j2" @@ -53,6 +54,7 @@ mode: "0750" when: - ansible_pkg_mgr != "apt" + - ansible_pkg_mgr != "portage" - not galera_upgrade - name: Run galera secure @@ -62,6 +64,7 @@ warn: no when: - ansible_pkg_mgr != "apt" + - ansible_pkg_mgr != "portage" - not galera_upgrade tags: - skip_ansible_lint @@ -147,11 +150,20 @@ - Manage LB - Restart all mysql +# Safe to run multiple times, config has it's own checks +- name: initialize database (gentoo) + command: "emerge --config dev-db/mariadb" + failed_when: false + when: + - ansible_pkg_mgr == 'portage' + - name: Apply service defaults template: src: "mysql_defaults.j2" dest: "/etc/default/mariadb" mode: "0644" + when: + - ansible_pkg_mgr != 'portage' notify: - Manage LB - Restart all mysql @@ -163,6 +175,8 @@ dest: "/etc/default/mysql" state: "link" force: "yes" + when: + - ansible_pkg_mgr != 'portage' - name: remove default mysql_safe_syslog file: @@ -170,8 +184,8 @@ state: absent - name: Create new cluster tool - copy: - src: "galera_new_cluster" + template: + src: "galera_new_cluster.j2" dest: "/usr/local/bin/galera_new_cluster" mode: "0750" diff --git a/tasks/galera_setup.yml b/tasks/galera_setup.yml index 2df8daf0..0465c118 100644 --- a/tasks/galera_setup.yml +++ b/tasks/galera_setup.yml @@ -56,7 +56,7 @@ no_log: True - name: Run MySQL Upgrade - command: "/usr/bin/mysql_upgrade" + command: "/usr/bin/mysql_upgrade -h 127.0.0.1" register: galera_mysql_upgrade changed_when: - not galera_mysql_upgrade.stdout | search("already upgraded") diff --git a/files/galera_new_cluster b/templates/galera_new_cluster.j2 similarity index 92% rename from files/galera_new_cluster rename to templates/galera_new_cluster.j2 index 1e2ea7fe..78ff5e2f 100644 --- a/files/galera_new_cluster +++ b/templates/galera_new_cluster.j2 @@ -47,16 +47,16 @@ EOF trap cleanup EXIT INT TERM EXIT_CODE=0 -if ! systemctl status mysql > /dev/null; then +if ! systemctl status {{ mysql_service_name }}> /dev/null; then systemctl set-environment _WSREP_NEW_CLUSTER='--wsrep-new-cluster' if grep -rniq -e suse -e opensuse /etc/os-release; then bootstrap_opts fi - if systemctl start mysql; then + if systemctl start {{ mysql_service_name }}; then EXIT_CODE=3 else echo "Cluster bootstrap failed." - systemctl status mysql + systemctl status {{ mysql_service_name }} exit 99 fi fi diff --git a/templates/galera_secure_node.j2 b/templates/galera_secure_node.j2 index 59b9ca5d..c31368af 100644 --- a/templates/galera_secure_node.j2 +++ b/templates/galera_secure_node.j2 @@ -17,12 +17,12 @@ set -ev STOP_MYSQL=false -if ! systemctl status mysql; then +if ! systemctl status {{ mysql_service_name }}; then STOP_MYSQL=true systemctl set-environment MYSQLD_OPTS="--bind-address=127.0.0.1" - systemctl start mysql + systemctl start {{ mysql_service_name }} sleep 10 - systemctl status mysql + systemctl status {{ mysql_service_name }} fi if mysqladmin --no-defaults --port=3306 --socket=/var/run/mysqld/mysqld.sock --host=127.0.0.1 --user=root password "{{ galera_root_password }}"; then @@ -38,7 +38,7 @@ if mysqladmin --no-defaults --port=3306 --socket=/var/run/mysqld/mysqld.sock --h fi if [ "${STOP_MYSQL}" = true ]; then - systemctl stop mysql + systemctl stop {{ mysql_service_name }} fi # Create a marker file to ensure this script is not run again diff --git a/templates/my.cnf.j2 b/templates/my.cnf.j2 index 91d33f3f..86be78bc 100644 --- a/templates/my.cnf.j2 +++ b/templates/my.cnf.j2 @@ -29,6 +29,7 @@ collation-server = utf8_general_ci init-connect = 'SET NAMES utf8' character-set-server = utf8 datadir = /var/lib/mysql +tmpdir = /var/lib/mysql bind-address = :: {% if galera_server_id is defined %} server-id = {{ galera_server_id }} diff --git a/vars/gentoo.yml b/vars/gentoo.yml new file mode 100644 index 00000000..512b431b --- /dev/null +++ b/vars/gentoo.yml @@ -0,0 +1,58 @@ +--- +# Copyright 2019, Matthew Thode +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +## APT Cache Options +cache_timeout: 600 + +# Default private device setting +_galera_disable_privatedevices: yes + +galera_server_required_distro_packages: + - sys-apps/xinetd + +galera_etc_conf_file: "/etc/mysql/my.cnf" +galera_etc_include_dir: "/etc/mysql/conf.d" +galera_var_run_socket: "/var/run/mysqld/mysqld.sock" + +# The package name for mariaDB is set as a variable +# so that it can be used in debconf later in the +# "galera_common" role. +_galera_mariadb_server_package: "dev-db/mariadb" + +# NB This is specifically galera_server_mariadb_distro_packages as these +# packages only get installed during the galera play - this is because of +# the preseed task and the service startup control used when installing +# mariadb-galera-server and galera. +galera_server_mariadb_distro_packages: + - "{{ galera_mariadb_server_package }}" + - sys-cluster/galera + - net-misc/rsync + - net-misc/socat + - dev-python/mysql-python + +# The packages to uninstall during an upgrade from a previous version +galera_server_upgrade_packages_remove: + +galera_mariadb_service_name: "mariadb" + +galera_server_percona_distro_packages: + - dev-db/percona-toolkit + - dev-db/percona-xtrabackup-bin + - "{{ (galera_xtrabackup_compression | bool) | ternary('app-arch/qpress', '') }}" + +galera_wsrep_provider: "/usr/lib64/galera/libgalera_smm.so" + +_use_percona_upstream: no +mysql_service_name: mariadb diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 00000000..44f92253 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1 @@ +mysql_service_name: mysql