From 988d319a8fe8adb5d54af441b11b2f468ffe6f4b56738495b13e7f24bd34c5e2 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Fri, 12 Feb 2021 11:01:43 +0000 Subject: [PATCH] - Improve the logic used to apply the presets (bsc#1177039) Before presests were applied at a) package installation b) new units introduced via a package update (but after making sure that it was not a SysV initscript being converted). The problem is that a) didn't handle package a renaming or split properly since the package with the new name is installed rather being updated and therefore the presets were applied even if they were already with the old name. We now cover this case (and the other ones) by applying presets only if the units are new and the services are not being migrated. This regardless of whether this happens during an install or an update. OBS-URL: https://build.opensuse.org/package/show/Base:System/systemd-rpm-macros?expand=0&rev=59 --- macros.systemd | 35 ++++++++++++++++++++--------------- systemd-rpm-macros.changes | 18 ++++++++++++++++++ systemd-rpm-macros.spec | 2 +- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/macros.systemd b/macros.systemd index 81db94e..586b1e8 100644 --- a/macros.systemd +++ b/macros.systemd @@ -1,4 +1,4 @@ -# -*- Mode: makefile; indent-tabs-mode: t -*- */ +# -*- Mode: rpm-spec; indent-tabs-mode: t -*- */ # RPM macros for packages installing systemd unit files # ### @@ -68,8 +68,17 @@ OrderWithRequires(postun): systemd \ fi \ %{nil} +# Figure out when presets need to be applied. This information is only +# recorded during %pre and is actually applied during %post. +# +# Presets might need to be applied during package install but also +# during package update. On update, packages might introduce new +# services but we need to make sure that's not happening during the +# migration of SysV initscripts. On package install, presets might +# have been already applied because of package renaming or split. +# %service_add_pre() \ -if [ $1 -gt 1 -a -x /usr/bin/systemctl ]; then \ +if [ -x /usr/bin/systemctl ]; then \ for service in %{?*} ; do \ if [ ! -e "/usr/lib/systemd/system/$service" ] && \ [ ! -e "/etc/init.d/${service%.*}" ]; then \ @@ -80,22 +89,18 @@ if [ $1 -gt 1 -a -x /usr/bin/systemctl ]; then \ fi \ %{nil} -# On install, tell systemd to reload its unit files +# Apply the presets if %pre told us to do so. # %service_add_post() \ if [ -x /usr/bin/systemctl ]; then \ - if [ $1 -eq 1 ]; then \ - /usr/bin/systemctl preset %{?*} || : \ - else \ - for service in %{?*} ; do \ - if [ -e "/run/systemd/rpm/needs-preset/$service" ]; then \ - /usr/bin/systemctl preset "$service" || : \ - fi \ - done \ - rm -fr /run/systemd/rpm/needs-preset \ - \ - /usr/lib/systemd/systemd-sysv-convert --apply %{?*} || : \ - fi \ + for service in %{?*} ; do \ + if [ -e "/run/systemd/rpm/needs-preset/$service" ]; then \ + /usr/bin/systemctl preset "$service" || : \ + rm -f /run/systemd/rpm/needs-preset/$service \ + else \ + /usr/lib/systemd/systemd-sysv-convert --apply %{?*} || : \ + fi \ + done \ fi \ %{nil} diff --git a/systemd-rpm-macros.changes b/systemd-rpm-macros.changes index 4cd5fd7..51206a1 100644 --- a/systemd-rpm-macros.changes +++ b/systemd-rpm-macros.changes @@ -1,3 +1,21 @@ +------------------------------------------------------------------- +Fri Feb 12 10:23:35 UTC 2021 - Franck Bui + +- Improve the logic used to apply the presets (bsc#1177039) + + Before presests were applied at a) package installation b) new units + introduced via a package update (but after making sure that it was + not a SysV initscript being converted). + + The problem is that a) didn't handle package a renaming or split + properly since the package with the new name is installed rather + being updated and therefore the presets were applied even if they + were already with the old name. + + We now cover this case (and the other ones) by applying presets only + if the units are new and the services are not being migrated. This + regardless of whether this happens during an install or an update. + ------------------------------------------------------------------- Mon Nov 23 20:33:21 UTC 2020 - Franck Bui diff --git a/systemd-rpm-macros.spec b/systemd-rpm-macros.spec index f7d4fff..34dfb11 100644 --- a/systemd-rpm-macros.spec +++ b/systemd-rpm-macros.spec @@ -1,7 +1,7 @@ # # spec file for package systemd-rpm-macros # -# Copyright (c) 2020 SUSE LLC +# Copyright (c) 2021 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed