From 8271919b17b5a0662e2baa4fd66d292d3dcf1e24 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Wed, 26 Jan 2022 15:21:24 +0200 Subject: [PATCH] Use systemd_service role for overrides Replace placing templates for systemd overrides with systemd_service role, that will handle overrides for us in more convenient and unified way. Change-Id: I2759b1949e9ecc98953f414c6f9838aed7dd8499 --- defaults/main.yml | 6 +++ ...bitmq_init_overrides-74ce479a2dcf304c.yaml | 6 +++ tasks/rabbitmq_post_install.yml | 54 +++++++------------ templates/limits.conf.j2 | 4 -- templates/rabbitmq-server.service.j2 | 18 ------- templates/systemd-restart-on-failure.conf.j2 | 4 -- 6 files changed, 31 insertions(+), 61 deletions(-) create mode 100644 releasenotes/notes/rabbitmq_init_overrides-74ce479a2dcf304c.yaml delete mode 100644 templates/limits.conf.j2 delete mode 100644 templates/rabbitmq-server.service.j2 delete mode 100644 templates/systemd-restart-on-failure.conf.j2 diff --git a/defaults/main.yml b/defaults/main.yml index c512fb96..a21f18b1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -284,6 +284,12 @@ rabbitmq_port_bindings: tcp_listeners: "0.0.0.0": 5672 +rabbitmq_init_overrides: + Service: + LimitNOFILE: "{{ rabbitmq_ulimit }}" + Restart: on-failure + RestartSec: 2 + # Mnesia configuration # The Mnesia dump_log_write_threshold option controls # how often the dumping occurs diff --git a/releasenotes/notes/rabbitmq_init_overrides-74ce479a2dcf304c.yaml b/releasenotes/notes/rabbitmq_init_overrides-74ce479a2dcf304c.yaml new file mode 100644 index 00000000..9d54339b --- /dev/null +++ b/releasenotes/notes/rabbitmq_init_overrides-74ce479a2dcf304c.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Added variable ``rabbitmq_init_overrides`` that allows to control rabbitmq + overrides that will be applied to the systemd service. + Previously values were hardcoded without possibility for override. diff --git a/tasks/rabbitmq_post_install.yml b/tasks/rabbitmq_post_install.yml index b3dbb4be..9a0e20d8 100644 --- a/tasks/rabbitmq_post_install.yml +++ b/tasks/rabbitmq_post_install.yml @@ -13,16 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Create rabbitmq systemd service config dir - file: - path: "/etc/systemd/system/rabbitmq-server.service.d" - state: "directory" - group: "root" - owner: "root" - mode: "0755" - tags: - - rabbitmq-config - - name: Create rabbitmq config register: rabbit_config template: @@ -45,32 +35,26 @@ path: /etc/rabbitmq/rabbitmq.config state: absent -- name: Apply resource limits (systemd) - template: - src: "limits.conf.j2" - dest: "/etc/systemd/system/rabbitmq-server.service.d/limits.conf" - register: rabbit_resource_limit - tags: - - rabbitmq-config +# TODO(noonedeadpunk): Remove task after Z release +- name: Remove old systemd overrides + file: + path: "/etc/systemd/system/rabbitmq-server.service.d/{{ item }}" + state: absent + with_items: + - limits.conf + - systemd-restart-on-failure.conf + when: rabbitmq_upgrade | bool -- name: Add automatic restart on failure - template: - src: systemd-restart-on-failure.conf.j2 - dest: "/etc/systemd/system/rabbitmq-server.service.d/systemd-restart-on-failure.conf" - register: rabbit_restart_on_failure - tags: - - rabbitmq-config - -- name: Reload the systemd daemon - systemd: - daemon_reload: yes - when: - - rabbit_resource_limit is changed - - rabbit_restart_on_failure is changed - tags: - - rabbitmq-config - # don't trigger ANSIBLE0016 - - skip_ansible_lint +- name: Apply systemctl overrides + import_role: + name: systemd_service + vars: + systemd_user_name: "{{ rabbit_system_user_name }}" + systemd_group_name: "{{ rabbit_system_group_name }}" + systemd_services: + - service_name: rabbitmq-server + systemd_overrides_only: true + systemd_overrides: "{{ rabbitmq_init_overrides }}" - name: Configure rabbitmq plugins community.rabbitmq.rabbitmq_plugin: diff --git a/templates/limits.conf.j2 b/templates/limits.conf.j2 deleted file mode 100644 index 94e8ab65..00000000 --- a/templates/limits.conf.j2 +++ /dev/null @@ -1,4 +0,0 @@ -# {{ ansible_managed }} - -[Service] -LimitNOFILE={{ rabbitmq_ulimit }} diff --git a/templates/rabbitmq-server.service.j2 b/templates/rabbitmq-server.service.j2 deleted file mode 100644 index 603403f2..00000000 --- a/templates/rabbitmq-server.service.j2 +++ /dev/null @@ -1,18 +0,0 @@ -[Unit] -Description=RabbitMQ broker -After=syslog.target network.target -Conflicts=epmd.socket -Conflicts=epmd.service - -[Service] -Type=notify -User={{ rabbit_system_user_name }} -Group={{ rabbit_system_group_name }} -LimitNOFILE=65535 -NotifyAccess=all -WorkingDirectory=/var/lib/rabbitmq -ExecStart=/usr/sbin/rabbitmq-server -ExecStop=/usr/sbin/rabbitmqctl stop - -[Install] -WantedBy=multi-user.target diff --git a/templates/systemd-restart-on-failure.conf.j2 b/templates/systemd-restart-on-failure.conf.j2 deleted file mode 100644 index 8acdc0f3..00000000 --- a/templates/systemd-restart-on-failure.conf.j2 +++ /dev/null @@ -1,4 +0,0 @@ -# {{ ansible_managed }} -[Service] -Restart=on-failure -RestartSec=2