Currently we disable stock emergency.service because interrupting the
boot process will stop us from entering kdump capture script. But this
isn't promising, when a mandatory target/service fails and emergency is
disabled, systemd has no service to run and appears hang to us.
A better approach is to write our own error handling service and act
different according to our configured default action in kdump.conf.
This patch introduce a kdump error handling script and an emergency
service. This emergency.service unit is overriding the existing one when
building kdump initramfs, and when it's started it will call the error
handling script.
Signed-off-by: WANG Chao <chaowang(a)redhat.com>
---
dracut-kdump-emergency.service | 32 ++++++++++++++++++++++++++++++++
dracut-kdump-error-handler.sh | 10 ++++++++++
dracut-module-setup.sh | 3 +++
kexec-tools.spec | 5 ++++-
4 files changed, 49 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..a29b14a
--- /dev/null
+++ b/dracut-kdump-emergency.service
@@ -0,0 +1,32 @@
+# This file is part of systemd.
+#
+# systemd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+
+# See systemd.special(7) for details
+
+[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..2c55b04
--- /dev/null
+++ b/dracut-kdump-error-handler.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+. /lib/kdump-lib.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 2a16900..0a03bfa 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -546,6 +546,9 @@ install() {
inst "/sbin/vmcore-dmesg" "/sbin/vmcore-dmesg"
inst_hook pre-pivot 9999 "$moddir/kdump.sh"
inst "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.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 a1490db..0e6d25c 100644
--- a/kexec-tools.spec
+++ b/kexec-tools.spec
@@ -34,6 +34,8 @@ Source22: kdump-dep-generator.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
@@ -188,7 +190,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.0