11c4653
From 631d2b05ec5195d1f8f8fbff8a2dfcbf23d0b7aa Mon Sep 17 00:00:00 2001
11c4653
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
11c4653
Date: Wed, 26 Jul 2023 09:02:04 +0200
11c4653
Subject: [PATCH] rpm: add %systemd_postun_with_reload and
11c4653
 %systemd_user_postun_with_reload
11c4653
11c4653
For some units, the package would like to issue a reload. The machinery was
11c4653
already in place since c9615f73521986b3607b852c139036d58973043c:
11c4653
11c4653
  systemctl reload-or-restart --marked
11c4653
11c4653
  Enqueues restart jobs for all units that have the 'needs-restart'
11c4653
  mark, and reload jobs for units that have the 'needs-reload' mark.
11c4653
  When a unit marked for reload does not support reload, restart will
11c4653
  be queued.
11c4653
11c4653
The new macros allow a reload to be issued instead of a restart.
11c4653
11c4653
Based on the discussion on fedora-devel:
11c4653
https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/message/IJSUGIEJNYZZRE53FF4YFUEBRHRAVIXR/
11c4653
11c4653
Tested using dummy package https://github.com/keszybz/rpm-test-reload.
11c4653
---
11c4653
 src/rpm/macros.systemd.in        | 16 ++++++++++++++++
11c4653
 src/rpm/systemd-update-helper.in | 22 ++++++++++++++++++++++
11c4653
 2 files changed, 38 insertions(+)
11c4653
11c4653
diff --git a/src/rpm/macros.systemd.in b/src/rpm/macros.systemd.in
11c4653
index c07541c7286c..f05553f557e9 100644
11c4653
--- a/src/rpm/macros.systemd.in
11c4653
+++ b/src/rpm/macros.systemd.in
11c4653
@@ -101,6 +101,22 @@ if [ $1 -ge 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \
11c4653
 fi \
11c4653
 %{nil}
11c4653
 
11c4653
+%systemd_postun_with_reload() \
11c4653
+%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun_with_reload}} \
11c4653
+if [ $1 -ge 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \
11c4653
+    # Package upgrade, not uninstall \
11c4653
+    {{SYSTEMD_UPDATE_HELPER_PATH}} mark-reload-system-units %{?*} || : \
11c4653
+fi \
11c4653
+%{nil}
11c4653
+
11c4653
+%systemd_user_postun_with_reload() \
11c4653
+%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_postun_with_reload}} \
11c4653
+if [ $1 -ge 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \
11c4653
+    # Package upgrade, not uninstall \
11c4653
+    {{SYSTEMD_UPDATE_HELPER_PATH}} mark-reload-user-units %{?*} || : \
11c4653
+fi \
11c4653
+%{nil}
11c4653
+
11c4653
 %udev_hwdb_update() %{nil}
11c4653
 
11c4653
 %udev_rules_update() %{nil}
11c4653
diff --git a/src/rpm/systemd-update-helper.in b/src/rpm/systemd-update-helper.in
11c4653
index c623a5ea1722..c81e16c3d3ff 100755
11c4653
--- a/src/rpm/systemd-update-helper.in
11c4653
+++ b/src/rpm/systemd-update-helper.in
11c4653
@@ -47,6 +47,15 @@ case "$command" in
11c4653
         wait
11c4653
         ;;
11c4653
 
11c4653
+    mark-reload-system-units)
11c4653
+        [ -d /run/systemd/system ] || exit 0
11c4653
+
11c4653
+        for unit in "$@"; do
11c4653
+            systemctl set-property "$unit" Markers=+needs-reload &
11c4653
+        done
11c4653
+        wait
11c4653
+        ;;
11c4653
+
11c4653
     mark-restart-user-units)
11c4653
         [ -d /run/systemd/system ] || exit 0
11c4653
 
11c4653
@@ -60,6 +69,19 @@ case "$command" in
11c4653
         wait
11c4653
         ;;
11c4653
 
11c4653
+    mark-reload-user-units)
11c4653
+        [ -d /run/systemd/system ] || exit 0
11c4653
+
11c4653
+        users=$(systemctl list-units 'user@*' --legend=no | sed -n -r 's/.*user@([0-9]+).service.*/\1/p')
11c4653
+        for user in $users; do
11c4653
+            for unit in "$@"; do
11c4653
+                SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT_SEC}}s \
11c4653
+                        systemctl --user -M "$user@" set-property "$unit" Markers=+needs-reload &
11c4653
+            done
11c4653
+        done
11c4653
+        wait
11c4653
+        ;;
11c4653
+
11c4653
     system-reload-restart|system-reload|system-restart)
11c4653
         if [ -n "$*" ]; then
11c4653
             echo "Unexpected arguments for '$command': $*"