Now upon failure kdump script might not be called at all and it might
not be able to execute default action. It results in a hang.
Because we disable emergency shell and rely on kdump.sh being invoked
through dracut-pre-pivot hook. But it might happen that we never call
into dracut-pre-pivot hook because certain systemd targets could not
reach due to failure in their dependencies. In those cases error
handling code does not run and system hangs.
To solve this problem, we need to separate the error handling code from
dracut-pre-pivot hook, and every time when a failure shows up, the
separated code can be called by the emergency service.
By default systemd provides an emergency service which will drop us into
shell every time upon a critical failure. It's very convenient for us to
re-use the framework of systemd emergency, because we don't have to
touch the other parts of systemd. We can use our own script instead of
the default one.
This new scheme will overwrite emergency shell and replace with kdump
error handling code. And this code will do the error handling as needed.
Now, we will not rely on dracut-pre-pivot hook running always. Instead
whenever error happens and it is serious enough that emergency shell
needed to run, now kdump error handler will run.
Signed-off-by: WANG Chao <chaowang(a)redhat.com>
---
dracut-kdump-emergency.service | 23 +++++++++++++++++++++++
dracut-kdump-error-handler.sh | 10 ++++++++++
dracut-module-setup.sh | 3 +++
kexec-tools.spec | 5 ++++-
4 files changed, 40 insertions(+), 1 deletion(-)
create mode 100644 dracut-kdump-emergency.service
create mode 100755 dracut-kdump-error-handler.sh
diff --git a/dracut-kdump-emergency.service b/dracut-kdump-emergency.service
new file mode 100644
index 0000000..6c90420
--- /dev/null
+++ b/dracut-kdump-emergency.service
@@ -0,0 +1,23 @@
+[Unit]
+Description=Kdump Error Handler
+DefaultDependencies=no
+After=systemd-vconsole-setup.service
+Wants=systemd-vconsole-setup.service
+
+[Service]
+Environment=HOME=/
+Environment=DRACUT_SYSTEMD=1
+Environment=NEWROOT=/sysroot
+WorkingDirectory=/
+ExecStart=/bin/kdump-error-handler.sh
+ExecStopPost=-/usr/bin/systemctl --fail --no-block default
+Type=oneshot
+StandardInput=tty-force
+StandardOutput=inherit
+StandardError=inherit
+KillMode=process
+IgnoreSIGPIPE=no
+
+# Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash
+# terminates cleanly.
+KillSignal=SIGHUP
diff --git a/dracut-kdump-error-handler.sh b/dracut-kdump-error-handler.sh
new file mode 100755
index 0000000..2f0f1d1
--- /dev/null
+++ b/dracut-kdump-error-handler.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+. /lib/kdump-lib-initramfs.sh
+
+set -o pipefail
+export PATH=$PATH:$KDUMP_SCRIPT_DIR
+
+get_kdump_confs
+do_default_action
+do_final_action
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 84bf975..4799219 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -556,6 +556,9 @@ install() {
inst_hook pre-pivot 9999 "$moddir/kdump.sh"
inst "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.sh"
inst "/lib/kdump/kdump-lib-initramfs.sh"
"/lib/kdump-lib-initramfs.sh"
+ inst "$moddir/kdump-error-handler.sh"
"/usr/bin/kdump-error-handler.sh"
+ # Replace existing emergency service
+ cp "$moddir/kdump-emergency.service"
"$initdir/$systemdsystemunitdir/emergency.service"
# Check for all the devices and if any device is iscsi, bring up iscsi
# target. Ideally all this should be pushed into dracut iscsi module
diff --git a/kexec-tools.spec b/kexec-tools.spec
index 5aa919c..2023874 100644
--- a/kexec-tools.spec
+++ b/kexec-tools.spec
@@ -36,6 +36,8 @@ Source24: kdump-lib-initramfs.sh
Source100: dracut-kdump.sh
Source101: dracut-module-setup.sh
Source102: dracut-monitor_dd_progress
+Source103: dracut-kdump-error-handler.sh
+Source104: dracut-kdump-emergency.service
Requires(post): systemd-units
Requires(preun): systemd-units
@@ -210,7 +212,8 @@ mkdir -p -m755
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpba
cp %{SOURCE100}
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix
%{SOURCE100}}
cp %{SOURCE101}
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix
%{SOURCE101}}
cp %{SOURCE102}
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix
%{SOURCE102}}
-
+cp %{SOURCE103}
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix
%{SOURCE103}}
+cp %{SOURCE104}
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix
%{SOURCE104}}
chmod 755
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix
%{SOURCE100}}
chmod 755
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix
%{SOURCE101}}
--
1.9.3