From 94eaeb726b9d7e3b4565aae95a3d5340f9366555 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Wed, 20 May 2026 13:54:04 +0200 Subject: [PATCH] preremove.sh: drain cf-agent before stopping cfengine3 umbrella MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A cf-agent process spawned by cf-execd can keep running after systemctl stop cf-execd.service, finish a policy run, and then call systemctl start cf-php-fpm.service. cf-php-fpm has Wants=cf-postgres.service, so systemd pulls cf-postgres back in as a dependency. cf-postgres fails to start (data dir being torn down) and Restart=always, RestartSec=10 keeps it looping. The loop continues into the next install's postinst, collides with the postinst-launched postgres, and the postinst's final pg_ctl stop fails with "PID file does not exist" — dpkg sees exit 1 and aborts: dpkg: error processing package cfengine-nova-hub (--install): installed cfengine-nova-hub package post-installation script subprocess returned error exit status 1 Fix: in prerm, stop cf-execd first so no new cf-agent runs spawn, then wait up to 60s for any in-progress cf-agent to drain (SIGKILL the survivor), and only then run the cfengine3 umbrella stop. cf-php-fpm stays up the whole time, so policy passes without re-triggering anything. Ticket: ENT-14108 Signed-off-by: Lars Erik Wik --- packaging/common/cfengine-hub/preremove.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packaging/common/cfengine-hub/preremove.sh b/packaging/common/cfengine-hub/preremove.sh index 46e6bfb0f..b8e6a15be 100644 --- a/packaging/common/cfengine-hub/preremove.sh +++ b/packaging/common/cfengine-hub/preremove.sh @@ -1,3 +1,16 @@ +# Drain in-flight cf-agent before stopping the cfengine3 umbrella: otherwise +# a running cf-agent can re-trigger cf-php-fpm (which Wants=cf-postgres), +# leaving cf-postgres in a Restart=always loop while the package is gone. +if use_systemd; then + /bin/systemctl stop cf-execd.service >/dev/null 2>&1 || true + t=60 + while [ $t -gt 0 ] && pgrep -x cf-agent >/dev/null 2>&1; do + sleep 1 + t=$((t - 1)) + done + pkill -KILL -x cf-agent >/dev/null 2>&1 || true +fi + cf_console platform_service cfengine3 stop if use_systemd && [ -e /usr/lib/systemd/system/cfengine3-web.service ]; then # When using systemd, the services are split in two, and although both will