From 54727e148fcb7bfe9ccd860a60b9f1fd43ebf563 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Mon, 22 Jan 2024 09:03:15 -0600 Subject: [PATCH] r/nut{,-monitor}: Enable nut.target Recent versions of NUT have a *nut.target* unit that collects all of the NUT-related services. Enabling any of the services individually does effectively nothing, as it only adds the service as a `Wants` dependency for *nut.target*, and that unit already has dependencies for all of them. Thus, in order for the service to start at boot, *nut.target* has to be enabled instead. In situations where only *nut-monitor* should be enabled, enabling *nut.target* is inappropriate, since that enables *nut-driver* and *nut-server* as well. It's not clear why upstream made this change (it was part of a [HUGE pull request][0]), but restoring the desired behavior is easy enough by clearing the dependencies from *nut.target*. Services that we want to start automatically can still be enabled individually, and will start as long as *nut.target* is enabled. [0]: https://github.com/networkupstools/nut/pull/330 --- roles/nut-common/files/nut-reset-deps.conf | 3 +++ roles/nut-common/tasks/main.yml | 26 ++++++++++++++++++++++ roles/nut-monitor/tasks/main.yml | 4 ++++ roles/nut/tasks/main.yml | 4 ++++ 4 files changed, 37 insertions(+) create mode 100644 roles/nut-common/files/nut-reset-deps.conf create mode 100644 roles/nut-common/tasks/main.yml diff --git a/roles/nut-common/files/nut-reset-deps.conf b/roles/nut-common/files/nut-reset-deps.conf new file mode 100644 index 0000000..ecbab1b --- /dev/null +++ b/roles/nut-common/files/nut-reset-deps.conf @@ -0,0 +1,3 @@ +[Unit] +Wants= +Requires= diff --git a/roles/nut-common/tasks/main.yml b/roles/nut-common/tasks/main.yml new file mode 100644 index 0000000..2042217 --- /dev/null +++ b/roles/nut-common/tasks/main.yml @@ -0,0 +1,26 @@ +- name: ensure nut.target configuration drop-in directory exists + file: + path: /etc/systemd/system/nut.target.d + owner: root + group: root + mode: u=rwx,go=rx + state: directory + tags: + - systemd + +- name: ensure nut.target dependencies are reset + copy: + src: nut-reset-deps.conf + dest: /etc/systemd/system/nut.target.d/reset-deps.conf + owner: root + group: root + mode: u=rw,go=r + tags: + - systemd + +- name: ensure nut.target is enabled + systemd: + name: nut.target + enabled: true + tags: + - service diff --git a/roles/nut-monitor/tasks/main.yml b/roles/nut-monitor/tasks/main.yml index ac3981e..1b154dc 100644 --- a/roles/nut-monitor/tasks/main.yml +++ b/roles/nut-monitor/tasks/main.yml @@ -33,3 +33,7 @@ enabled: true tags: - service + +- name: apply nut-common role + include_role: + name: nut-common diff --git a/roles/nut/tasks/main.yml b/roles/nut/tasks/main.yml index 38dcde4..1fc4dcf 100644 --- a/roles/nut/tasks/main.yml +++ b/roles/nut/tasks/main.yml @@ -60,3 +60,7 @@ permanent: true tags: - firewalld + +- name: apply nut-common role + include_role: + name: nut-common