From 37b37f6e66d1d2d85b3eb2178787aec03221d2a6 Mon Sep 17 00:00:00 2001 From: Adam Dej Date: Wed, 11 Jul 2018 15:58:41 +0200 Subject: [PATCH] __systemd_unit: fix crash when transitioning to state=absent This type tried to disable an unit after it has removed it, which failed. Now the removal happens in gencode-remote, after the unit has been stopped and disabled. --- cdist/conf/type/__systemd_unit/gencode-remote | 2 ++ cdist/conf/type/__systemd_unit/manifest | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__systemd_unit/gencode-remote b/cdist/conf/type/__systemd_unit/gencode-remote index c608d9b3..9c64b6c4 100644 --- a/cdist/conf/type/__systemd_unit/gencode-remote +++ b/cdist/conf/type/__systemd_unit/gencode-remote @@ -25,6 +25,8 @@ current_enablement_state=$(cat "${__object}/explorer/enablement-state") if [ "${state}" = "absent" ]; then if [ ! -z "${current_enablement_state}" ]; then echo "systemctl --now disable ${name}" + echo "rm -f /etc/systemd/system/${name}" + echo "systemctl daemon-reload" fi exit 0 diff --git a/cdist/conf/type/__systemd_unit/manifest b/cdist/conf/type/__systemd_unit/manifest index 8b136605..7739c3d8 100644 --- a/cdist/conf/type/__systemd_unit/manifest +++ b/cdist/conf/type/__systemd_unit/manifest @@ -30,7 +30,9 @@ name="${__object_id}" source=$(cat "${__object}/parameter/source") state=$(cat "${__object}/parameter/state") -if [ -z "${source}" ] && [ "${state}" != "absent" ]; then +# The unit must be disabled before removing its unit file. The unit file is +# therefore removed by gencode-remote of this type, not here. +if [ -z "${source}" ] || [ "${state}" = "absent" ]; then exit 0 fi