From 11c465372ac03d7729bf546ec00bb6196dbf3468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 23 Aug 2023 09:12:42 +0200 Subject: [PATCH] Actually reload user managers and backport unit reload macros The macro expansions would only work when compiled with a recent version of systemd. We don't want to create a dependency loop like this, let's just expand the string manually. Also backport the patch adding %systemd_postun_with_reload and %systemd_user_postun_with_reload so a FPC documentation change can be filed. --- ...2b05ec5195d1f8f8fbff8a2dfcbf23d0b7aa.patch | 94 +++++++++++++++++++ systemd.spec | 11 ++- 2 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 631d2b05ec5195d1f8f8fbff8a2dfcbf23d0b7aa.patch diff --git a/631d2b05ec5195d1f8f8fbff8a2dfcbf23d0b7aa.patch b/631d2b05ec5195d1f8f8fbff8a2dfcbf23d0b7aa.patch new file mode 100644 index 0000000..81de92f --- /dev/null +++ b/631d2b05ec5195d1f8f8fbff8a2dfcbf23d0b7aa.patch @@ -0,0 +1,94 @@ +From 631d2b05ec5195d1f8f8fbff8a2dfcbf23d0b7aa Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= +Date: Wed, 26 Jul 2023 09:02:04 +0200 +Subject: [PATCH] rpm: add %systemd_postun_with_reload and + %systemd_user_postun_with_reload + +For some units, the package would like to issue a reload. The machinery was +already in place since c9615f73521986b3607b852c139036d58973043c: + + systemctl reload-or-restart --marked + + Enqueues restart jobs for all units that have the 'needs-restart' + mark, and reload jobs for units that have the 'needs-reload' mark. + When a unit marked for reload does not support reload, restart will + be queued. + +The new macros allow a reload to be issued instead of a restart. + +Based on the discussion on fedora-devel: +https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/message/IJSUGIEJNYZZRE53FF4YFUEBRHRAVIXR/ + +Tested using dummy package https://github.com/keszybz/rpm-test-reload. +--- + src/rpm/macros.systemd.in | 16 ++++++++++++++++ + src/rpm/systemd-update-helper.in | 22 ++++++++++++++++++++++ + 2 files changed, 38 insertions(+) + +diff --git a/src/rpm/macros.systemd.in b/src/rpm/macros.systemd.in +index c07541c7286c..f05553f557e9 100644 +--- a/src/rpm/macros.systemd.in ++++ b/src/rpm/macros.systemd.in +@@ -101,6 +101,22 @@ if [ $1 -ge 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ + fi \ + %{nil} + ++%systemd_postun_with_reload() \ ++%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun_with_reload}} \ ++if [ $1 -ge 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ ++ # Package upgrade, not uninstall \ ++ {{SYSTEMD_UPDATE_HELPER_PATH}} mark-reload-system-units %{?*} || : \ ++fi \ ++%{nil} ++ ++%systemd_user_postun_with_reload() \ ++%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_postun_with_reload}} \ ++if [ $1 -ge 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ ++ # Package upgrade, not uninstall \ ++ {{SYSTEMD_UPDATE_HELPER_PATH}} mark-reload-user-units %{?*} || : \ ++fi \ ++%{nil} ++ + %udev_hwdb_update() %{nil} + + %udev_rules_update() %{nil} +diff --git a/src/rpm/systemd-update-helper.in b/src/rpm/systemd-update-helper.in +index c623a5ea1722..c81e16c3d3ff 100755 +--- a/src/rpm/systemd-update-helper.in ++++ b/src/rpm/systemd-update-helper.in +@@ -47,6 +47,15 @@ case "$command" in + wait + ;; + ++ mark-reload-system-units) ++ [ -d /run/systemd/system ] || exit 0 ++ ++ for unit in "$@"; do ++ systemctl set-property "$unit" Markers=+needs-reload & ++ done ++ wait ++ ;; ++ + mark-restart-user-units) + [ -d /run/systemd/system ] || exit 0 + +@@ -60,6 +69,19 @@ case "$command" in + wait + ;; + ++ mark-reload-user-units) ++ [ -d /run/systemd/system ] || exit 0 ++ ++ users=$(systemctl list-units 'user@*' --legend=no | sed -n -r 's/.*user@([0-9]+).service.*/\1/p') ++ for user in $users; do ++ for unit in "$@"; do ++ SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT_SEC}}s \ ++ systemctl --user -M "$user@" set-property "$unit" Markers=+needs-reload & ++ done ++ done ++ wait ++ ;; ++ + system-reload-restart|system-reload|system-restart) + if [ -n "$*" ]; then + echo "Unexpected arguments for '$command': $*" diff --git a/systemd.spec b/systemd.spec index 37545e2..f3c19c3 100644 --- a/systemd.spec +++ b/systemd.spec @@ -99,10 +99,12 @@ GIT_DIR=../../src/systemd/.git git diffab -M v233..master@{2017-06-15} -- hwdb/[ # than in the next section. Packit CI will drop any patches in this range before # applying upstream pull requests. -# https://github.com/systemd/systemd/issues/26488 +# Work-around for dracut issue: run generators directly when we are in initrd # https://bugzilla.redhat.com/show_bug.cgi?id=2164404 Patch0001: https://github.com/systemd/systemd/pull/26494.patch +# Backport of patches that allow reloading of units +Patch0002: https://github.com/systemd/systemd/pull/28521/commits/631d2b05ec5195d1f8f8fbff8a2dfcbf23d0b7aa.patch # Those are downstream-only patches, but we don't want them in packit builds: # https://bugzilla.redhat.com/show_bug.cgi?id=1738828 @@ -940,7 +942,12 @@ fi # FIXME: systemd-logind.service is excluded (https://github.com/systemd/systemd/pull/17558) -%systemd_user_daemon_reexec +# This is the explanded form of %%systemd_user_daemon_reexec. We +# can't use the macro because we define it ourselves. +if [ $1 -ge 1 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then + # Package upgrade, not uninstall + /usr/lib/systemd/systemd-update-helper user-reexec || : +fi %triggerun resolved -- systemd < 246.1-1 # This is for upgrades from previous versions before systemd-resolved became the default.