]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
rpm: restart services in %posttrans 18481/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 31 Jan 2021 11:11:36 +0000 (12:11 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 15 Feb 2021 19:49:14 +0000 (20:49 +0100)
This fixes a long-standing issue in packaging scriptlets: daemon-reload
was moved to the end of the transaction, but restarting services was still
straightaway after package installation.

https://bugzilla.redhat.com/show_bug.cgi?id=1614751

Note that daemon-reload is called twice. This wouldn't be hardly noticable,
except that now a bunch of units (at least in Fedora) generate very verbose
warnings about deprecated features. So we get those warnings twice…

reload-or-restart --needing-restart is also called twice, but the second call
is usually a noop, because the first clears the flag for restarted units. The
second call is necessary for the case where we only uninstall packages, and the
%transfiletriggerpostun trigger fires, but not the %transfiletriggerin
scriptlet.

Also note that this assumes that units are marked only for restart if paths
under @systemunitdir@ or /etc/systemd/system have been touched. I would prefer
make the trigger that does 'restart --needing-restart' fire always, but it
seems rpm doesn't have such functionality. (Except as a %transfiletrigger that
would trigger on "/*" to catch all transactions, but that seems ineffiecient
and ugly.)

src/rpm/macros.systemd.in
src/rpm/triggers.systemd.in
src/rpm/triggers.systemd.sh.in

index 1c40328db0f26ab34852be409651887c3c1fdea2..24996de10ab46710ddc670ef6832a70267721e26 100644 (file)
@@ -82,7 +82,9 @@ fi \
 %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun_with_restart}} \
 if [ $1 -ge 1 ] && [ -x @bindir@/systemctl ]; then \
         # Package upgrade, not uninstall \
-        @bindir@/systemctl try-restart %{?*} || : \
+        for unit in %{?*}; do \
+                @bindir@/systemctl set-property $unit Markers=+needs-restart || : \
+        done \
 fi \
 %{nil}
 
index 37f62cb1b7693716fd6712fd63ead31d2296b473..3a89f9169d7afb568c37cde1b8a0ec0a122f677d 100644 (file)
@@ -20,6 +20,13 @@ if posix.access("/run/systemd/system") then
     elseif pid > 0 then
         posix.wait(pid)
     end
+
+    pid = posix.fork()
+    if pid == 0 then
+        assert(posix.exec("%{_bindir}/systemctl", "reload-or-restart", "--marked"))
+    elseif pid > 0 then
+        posix.wait(pid)
+    end
 end
 
 %transfiletriggerpostun -P 1000100 -p <lua> -- @systemunitdir@ /etc/systemd/system
@@ -37,6 +44,17 @@ if posix.access("/run/systemd/system") then
     end
 end
 
+%transfiletriggerpostun -P 10000 -p <lua> -- @systemunitdir@ /etc/systemd/system
+-- We restart remaining services that should be restarted here.
+if posix.access("/run/systemd/system") then
+    pid = posix.fork()
+    if pid == 0 then
+        assert(posix.exec("%{_bindir}/systemctl", "reload-or-restart", "--marked"))
+    elseif pid > 0 then
+        posix.wait(pid)
+    end
+end
+
 %transfiletriggerin -P 100700 -p <lua> -- @sysusersdir@
 -- This script will process files installed in @sysusersdir@ to create
 -- specified users automatically. The priority is set such that it
index c1af5f43d3b10248558b05be882da626d476d24f..0080040de481ceb43f9805901b1dba0b78526a40 100644 (file)
@@ -16,6 +16,7 @@
 # so sometimes we will reload needlessly.
 if test -d "/run/systemd/system"; then
   %{_bindir}/systemctl daemon-reload || :
+  %{_bindir}/systemctl reload-or-restart --marked || :
 fi
 
 %transfiletriggerpostun -P 1000100 -- @systemunitdir@ /etc/systemd/system
@@ -28,6 +29,12 @@ if test -d "/run/systemd/system"; then
   %{_bindir}/systemctl daemon-reload || :
 fi
 
+%transfiletriggerpostun -P 10000 -- @systemunitdir@ /etc/systemd/system
+# We restart remaining services that should be restarted here.
+if test -d "/run/systemd/system"; then
+  %{_bindir}/systemctl reload-or-restart --marked || :
+fi
+
 %transfiletriggerin -P 1000700 -- @sysusersdir@
 # This script will process files installed in @sysusersdir@ to create
 # specified users automatically. The priority is set such that it