]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
rpm: add %systemd_postun_with_reload and %systemd_user_postun_with_reload
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 26 Jul 2023 07:02:04 +0000 (09:02 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 7 Aug 2023 10:12:55 +0000 (12:12 +0200)
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
src/rpm/systemd-update-helper.in

index c07541c7286cb2c3befe851e552dc824492e0121..f05553f557e9dd418af26744faa9fda0aafd33b7 100644 (file)
@@ -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}
index c623a5ea17227593b787065e269c821568469fa5..c81e16c3d3ffb68c7c07add817d49ff786eeac4d 100755 (executable)
@@ -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': $*"