From c4c89ffc497f274f12b2f41def7c4a44edabb7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20M=C3=A9ndez=20Hern=C3=A1ndez?= Date: Fri, 27 Mar 2026 15:21:57 +0100 Subject: [PATCH] Remove After=foreman.target to fix systemd ordering cycles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After=foreman.target was added in 805217d to ensure systemctl stop foreman.target blocks until all constituent services fully stop, preventing a rapid stop+start race. However, every service is also WantedBy=foreman.target, making After=foreman.target inherently circular: foreman.target cannot finish starting until its Wants are satisfied, but those services cannot start until foreman.target has started. This caused both start and stop ordering cycles, which systemd resolved by dropping jobs — leading to unclean postgresql shutdowns, stale postmaster.pid files, and the very race condition the original fix was trying to prevent. Remove After=foreman.target from all services. Stop ordering is preserved through inter-service After= relationships: all application services are After=redis.service postgresql.service (reversed: redis/postgresql stop after all application services). PartOf=foreman.target ensures services stop when foreman.target stops, and systemctl stop foreman.target waits for the full PartOf-propagated transaction to complete. Co-Authored-By: Claude Sonnet 4.6 --- src/roles/candlepin/tasks/main.yml | 2 +- src/roles/foreman/tasks/main.yaml | 5 ++--- src/roles/foreman/templates/foreman-recurring@.timer.j2 | 1 - src/roles/foreman_proxy/tasks/main.yaml | 1 - src/roles/postgresql/tasks/main.yml | 1 - src/roles/pulp/tasks/main.yaml | 6 +++--- src/roles/redis/tasks/main.yaml | 1 - 7 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/roles/candlepin/tasks/main.yml b/src/roles/candlepin/tasks/main.yml index 210adc4da..4b2628138 100644 --- a/src/roles/candlepin/tasks/main.yml +++ b/src/roles/candlepin/tasks/main.yml @@ -97,7 +97,7 @@ [Unit] PartOf=foreman.target Wants=redis.service postgresql.service - After=foreman.target redis.service postgresql.service + After=redis.service postgresql.service [Service] TimeoutStartSec=300 healthcheck: curl --fail --insecure https://localhost:23443/candlepin/status diff --git a/src/roles/foreman/tasks/main.yaml b/src/roles/foreman/tasks/main.yaml index db3e8ed44..43139ead5 100644 --- a/src/roles/foreman/tasks/main.yaml +++ b/src/roles/foreman/tasks/main.yaml @@ -127,7 +127,7 @@ [Unit] PartOf=foreman.target Wants=redis.service postgresql.service candlepin.service - After=foreman.target redis.service postgresql.service candlepin.service + After=redis.service postgresql.service candlepin.service notify: Restart foreman - name: Deploy Dynflow Container @@ -162,7 +162,7 @@ [Unit] PartOf=foreman.target Wants=redis.service postgresql.service - After=foreman.target redis.service postgresql.service + After=redis.service postgresql.service - | [Service] Restart=on-failure @@ -207,7 +207,6 @@ - | [Unit] PartOf=foreman.target - After=foreman.target StartLimitIntervalSec=0 - | [Service] diff --git a/src/roles/foreman/templates/foreman-recurring@.timer.j2 b/src/roles/foreman/templates/foreman-recurring@.timer.j2 index f870cbc09..c696d9698 100644 --- a/src/roles/foreman/templates/foreman-recurring@.timer.j2 +++ b/src/roles/foreman/templates/foreman-recurring@.timer.j2 @@ -1,7 +1,6 @@ [Unit] Description=Timer for Foreman recurring: {{ item.rake }} PartOf=foreman.target -After=foreman.target [Timer] Unit=foreman-recurring@{{ item.instance }}.service diff --git a/src/roles/foreman_proxy/tasks/main.yaml b/src/roles/foreman_proxy/tasks/main.yaml index 21079ea72..236b9377f 100644 --- a/src/roles/foreman_proxy/tasks/main.yaml +++ b/src/roles/foreman_proxy/tasks/main.yaml @@ -34,7 +34,6 @@ WantedBy=default.target foreman.target [Unit] PartOf=foreman.target - After=foreman.target notify: Restart Foreman Proxy - name: Create foreman-proxy.container.d folder diff --git a/src/roles/postgresql/tasks/main.yml b/src/roles/postgresql/tasks/main.yml index 7123c4ffc..9168d9075 100644 --- a/src/roles/postgresql/tasks/main.yml +++ b/src/roles/postgresql/tasks/main.yml @@ -43,7 +43,6 @@ WantedBy=default.target foreman.target [Unit] PartOf=foreman.target - After=foreman.target - name: Configure SSL certificates when: diff --git a/src/roles/pulp/tasks/main.yaml b/src/roles/pulp/tasks/main.yaml index 73ae96713..66dcad042 100644 --- a/src/roles/pulp/tasks/main.yaml +++ b/src/roles/pulp/tasks/main.yaml @@ -119,7 +119,7 @@ [Unit] PartOf=foreman.target Wants=redis.service postgresql.service - After=foreman.target redis.service postgresql.service + After=redis.service postgresql.service [Service] Restart=always RestartSec=3 @@ -150,7 +150,7 @@ [Unit] PartOf=foreman.target Wants=redis.service postgresql.service - After=foreman.target redis.service postgresql.service + After=redis.service postgresql.service [Service] Restart=always RestartSec=3 @@ -181,7 +181,7 @@ [Unit] PartOf=pulp-worker.target foreman.target Wants=redis.service postgresql.service - After=foreman.target redis.service postgresql.service + After=redis.service postgresql.service [Service] Restart=always RestartSec=3 diff --git a/src/roles/redis/tasks/main.yaml b/src/roles/redis/tasks/main.yaml index 3314f7fa2..93837c90c 100644 --- a/src/roles/redis/tasks/main.yaml +++ b/src/roles/redis/tasks/main.yaml @@ -30,7 +30,6 @@ WantedBy=default.target foreman.target [Unit] PartOf=foreman.target - After=foreman.target - name: Run daemon reload ansible.builtin.systemd: