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
This commit is contained in:
Dmitriy Rabotyagov 2022-01-26 15:21:24 +02:00
parent e707eecdd8
commit 8271919b17
6 changed files with 31 additions and 61 deletions

View File

@ -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

View File

@ -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.

View File

@ -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:

View File

@ -1,4 +0,0 @@
# {{ ansible_managed }}
[Service]
LimitNOFILE={{ rabbitmq_ulimit }}

View File

@ -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

View File

@ -1,4 +0,0 @@
# {{ ansible_managed }}
[Service]
Restart=on-failure
RestartSec=2