diff --git a/handlers/main.yml b/handlers/main.yml index f80f8242..6488b3f7 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -53,3 +53,8 @@ until: galera_restart_fall_back | success retries: 3 delay: 5 + +- name: Reload the systemd daemon + command: "systemctl daemon-reload" + when: + - pid1_name == "systemd" diff --git a/tasks/galera_post_install.yml b/tasks/galera_post_install.yml index 099cff82..97c86ce8 100644 --- a/tasks/galera_post_install.yml +++ b/tasks/galera_post_install.yml @@ -68,14 +68,54 @@ tags: - galera-config -# NOTE: (mancdaz) The target will need to change to /etc/default/mariadb -# for mariadb-10.1 -- name: Drop mariadb config(s) +- name: Drop limits config (upstart) + template: + src: "upstart.limits.conf.j2" + dest: "/etc/security/limits.conf" + when: + - pid1_name != "systemd" + notify: + - Restart mysql + tags: + - galera-config + +# NOTE: (mancdaz) REMOVE "/etc/default/mysql" when running MariaDB 10.1 +- name: Apply resource limits (upstart) template: src: "mysql_defaults.j2" - dest: "/etc/default/mysql" + dest: "{{ item }}" mode: "0644" - notify: Restart mysql + with_items: + - /etc/default/mysql + - /etc/default/mariadb + when: + - ansible_pkg_mgr == 'apt' + - pid1_name != "systemd" + notify: + - Restart mysql + tags: + - galera-config + +- name: Create mariadb systemd service config dir + file: + path: "/etc/systemd/system/mariadb.service.d" + state: "directory" + group: "root" + owner: "root" + mode: "0755" + when: + - pid1_name == "systemd" + +- name: Apply resource limits (systemd) + template: + src: "systemd.limits.conf.j2" + dest: "/etc/systemd/system/mariadb.service.d/limits.conf" + mode: "0644" + when: + - pid1_name == "systemd" + notify: + - Reload the systemd daemon + - Restart mysql tags: - galera-config diff --git a/tasks/galera_pre_install.yml b/tasks/galera_pre_install.yml index 94367b68..1a02bdf3 100644 --- a/tasks/galera_pre_install.yml +++ b/tasks/galera_pre_install.yml @@ -41,11 +41,3 @@ when: not use_percona_upstream | bool tags: - percona-apt-packages - -- name: Drop limits config - template: - src: "limits.conf.j2" - dest: "/etc/security/limits.conf" - notify: Restart mysql - tags: - - galera-config diff --git a/tasks/main.yml b/tasks/main.yml index f380d76b..cfb15dc6 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -35,6 +35,18 @@ tags: - always +- name: Check init system + command: cat /proc/1/comm + register: _pid1_name + tags: + - always + +- name: Set the name of pid1 + set_fact: + pid1_name: "{{ _pid1_name.stdout }}" + tags: + - always + - include: galera_upgrade_check.yml - include: galera_cluster_state.yml - include: galera_pre_install.yml diff --git a/templates/systemd.limits.conf.j2 b/templates/systemd.limits.conf.j2 new file mode 100644 index 00000000..b01a1663 --- /dev/null +++ b/templates/systemd.limits.conf.j2 @@ -0,0 +1,12 @@ +# {{ ansible_managed }} + +{%- set all_calculated_max_connections = [] %} +{%- for galera_node in galera_cluster_members %} + {%- set _ = all_calculated_max_connections.append((hostvars[galera_node]['ansible_processor_vcpus'] | int > 0) | ternary (ansible_processor_vcpus, 2) * 100) %} +{%- endfor %} +{%- set calculated_min_connections = all_calculated_max_connections | min %} +{%- set calculated_max_connections = galera_max_connections | default(calculated_min_connections) %} + +[Service] +LimitNOFILE={{ calculated_max_connections }} + diff --git a/templates/limits.conf.j2 b/templates/upstart.limits.conf.j2 similarity index 100% rename from templates/limits.conf.j2 rename to templates/upstart.limits.conf.j2