|
Zbigniew Jędrzejewski-Szmek |
03e93e |
From 18eb87fdddbcb03940b2009e6cb43852e8735e9a Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
From: Franck Bui <fbui@suse.com>
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
Date: Wed, 23 Nov 2016 16:31:24 +0100
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
Subject: [PATCH] core: consider SIGTERM as a clean exit status for
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
initrd-switch-root.service (#4713)
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
Since commit 1f0958f640b8717, systemd considers SIGTERM for short-running
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
services (aka Type=oneshot) as a failure.
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
This can be an issue with initrd-switch-root.service as the command run by this
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
service (in order to switch to the new rootfs) may still be running when
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
systemd does the switch.
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
However PID1 sends SIGTERM to all remaining processes right before
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
switching and initrd-switch-root.service can be one of those.
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
After systemd is reexecuted and its previous state is deserialized, systemd
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
notices that initrd-switch-root.service was killed with SIGTERM and considers
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
this as a failure which leads to the emergency shell.
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
To prevent this, this patch teaches systemd to consider a SIGTERM exit as a
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
clean one for this service.
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
It also removes "KillMode=none" since this is pretty useless as the service is
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
never stopped by systemd but it either exits normally or it's killed by a
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
SIGTERM as described previously.
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
(cherry picked from commit a4021390fef27f4136497328f2e35e79bc88855d)
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
---
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
units/initrd-switch-root.service.in | 8 +++++++-
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
1 file changed, 7 insertions(+), 1 deletion(-)
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
diff --git a/units/initrd-switch-root.service.in b/units/initrd-switch-root.service.in
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
index 82893dafb1..b89f2348c7 100644
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
--- a/units/initrd-switch-root.service.in
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+++ b/units/initrd-switch-root.service.in
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
@@ -17,4 +17,10 @@ AllowIsolate=yes
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
Type=oneshot
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
# we have to use "--force" here, otherwise systemd would umount /run
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
ExecStart=@rootbindir@/systemctl --no-block --force switch-root /sysroot
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
-KillMode=none
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+# Just before switching to the new rootfs, systemd might send us a TERM signal
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+# depending on how fast we are to execute the main command and exit. If we get
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+# the SIGTERM signal that simply means that we succeed but haven't got enough
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+# time to exit properly. Since systemd considers SIGTERM as a failure for
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+# short-running process (aka Type=oneshot), instruct it to ignore this case.
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
+SuccessExitStatus=SIGTERM
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
--
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
2.9.3
|
|
Zbigniew Jędrzejewski-Szmek |
03e93e |
|