Hi, All
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.
This patchset introduce a new kdump emergency service. It will override the existing emergency.service. When fatal error occurs, this emergency service will be triggered and systemd will isolate to emergency path.
This kdump emergency service can will read kdump.conf and act according to the configired "default action" (reboot/poweroff/halt/shell/dump_to_rootfs).
Along with this patchset, kdump-capture.service is introduced as a service unit to run kdump.sh. When kdump-capture.service fails, systemd will isolate to kdump emergency service. I copied all the dependencies from dracut-pre-pivot.service to kdump-capture.service so that kdump.sh will be called at the correct time window.
v2: Address several comments from Vivek: - split [patch 1] into 1/6 and 2/6 - remove several unnecessary lines in service unit. - modify the description of kdump-capture.service - introduce another kdump lib kdump-lib-2.sh used in 2nd kernel.
V3: Address several comments from Vivek: - update description of [PATCH 1/5] and [PATCH 5/5] - separate the patch of cleanup to kdump-lib-initramfs.sh
V4: Address several comments from Vivek and Dave: - meld the original [PATCH 3/5] into [PATCH 1/5] - add GPL license for kdump-error-handler.service and kdump-capture.service - separate the "x-initrd.mount" and "mount under /sysroot" patch to another patchset
WANG Chao (2): Introduce kdump error handling service Introduce kdump capture service
dracut-kdump-capture.service | 30 ++++++++++++++++++++++++++++++ dracut-kdump-emergency.service | 30 ++++++++++++++++++++++++++++++ dracut-kdump-error-handler.sh | 10 ++++++++++ dracut-kdump.sh | 9 ++------- dracut-module-setup.sh | 7 ++++++- kdump-lib-initramfs.sh | 34 ++++++++++++++++++++++++++++++---- kexec-tools.spec | 7 ++++++- 7 files changed, 114 insertions(+), 13 deletions(-) create mode 100644 dracut-kdump-capture.service create mode 100644 dracut-kdump-emergency.service create mode 100755 dracut-kdump-error-handler.sh
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@redhat.com --- dracut-kdump-emergency.service | 30 ++++++++++++++++++++++++++++++ dracut-kdump-error-handler.sh | 10 ++++++++++ dracut-kdump.sh | 4 ---- dracut-module-setup.sh | 3 +++ kdump-lib-initramfs.sh | 34 ++++++++++++++++++++++++++++++---- kexec-tools.spec | 5 ++++- 6 files changed, 77 insertions(+), 9 deletions(-) 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..4434b9e --- /dev/null +++ b/dracut-kdump-emergency.service @@ -0,0 +1,30 @@ +# 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. + +[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-kdump.sh b/dracut-kdump.sh index 08f4322..1fe91ab 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -4,10 +4,6 @@ exec &> /dev/console . /lib/dracut-lib.sh . /lib/kdump-lib-initramfs.sh
-if [ -f "$initdir/lib/dracut/no-emergency-shell" ]; then - rm -f -- $initdir/lib/dracut/no-emergency-shell -fi - set -o pipefail DUMP_RETVAL=0
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/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index b7f0e61..d8cae5c 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -1,6 +1,5 @@ # These variables and functions are useful in 2nd kernel
-. /lib/dracut-lib.sh . /lib/kdump-lib.sh
KDUMP_PATH="/var/crash" @@ -23,6 +22,7 @@ NEWROOT="/sysroot" get_kdump_confs() { local config_opt config_val + local user_specified_cc
while read config_opt config_val; do @@ -34,6 +34,7 @@ get_kdump_confs() ;; core_collector) [ -n "$config_val" ] && CORE_COLLECTOR="$config_val" + user_specified_cc=yes ;; sshkey) if [ -f "$config_val" ]; then @@ -55,7 +56,7 @@ get_kdump_confs() default) case $config_val in shell) - DEFAULT_ACTION="_emergency_shell kdump" + DEFAULT_ACTION="kdump_emergency_shell" ;; reboot) DEFAULT_ACTION="do_umount; reboot -f" @@ -67,12 +68,19 @@ get_kdump_confs() DEFAULT_ACTION="do_umount; poweroff -f" ;; dump_to_rootfs) - DEFAULT_ACTION="dump_fs $NEWROOT" + DEFAULT_ACTION="dump_to_rootfs" ;; esac ;; esac done < $KDUMP_CONF + + if is_ssh_dump_target || is_raw_dump_target; then + if [ -z "$user_specified_cc" ]; then + CORE_COLLECTOR="$CORE_COLLECTOR -F" + fi + fi + }
# dump_fs <mount point| device> @@ -122,6 +130,24 @@ save_vmcore_dmesg_fs() { fi }
+dump_to_rootfs() +{ + + echo "Kdump: trying to bring up rootfs device" + systemctl start dracut-initqueue + echo "Kdump: waiting for rootfs mount, will timeout after 90 seconds" + systemctl start sysroot.mount + + dump_fs $NEWROOT +} + +kdump_emergency_shell() +{ + echo "PS1="kdump:\${PWD}# "" >/etc/profile + /bin/dracut-emergency + rm -f /etc/profile +} + do_umount() { umount -Rf $NEWROOT @@ -129,7 +155,7 @@ do_umount()
do_default_action() { - wait_for_loginit + echo "Kdump: Error Occured, doing default action" eval $DEFAULT_ACTION }
diff --git a/kexec-tools.spec b/kexec-tools.spec index a613b43..b3081bb 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}}
On Tue, Jul 22, 2014 at 03:20:06PM +0800, WANG Chao wrote:
[..]
do_default_action() {
- wait_for_loginit
- echo "Kdump: Error Occured, doing default action"
Ho about following.
"Kdump: Executing default action $DEFAULT_ACTION"
I think error occurred is implied. And we should output an error message where actual error happened.
I had recommened similar message in RHEL6, I guess. Can you please look it up and try to keep message same.
Let us try our best to keep the messages consistent across all releases.
Thanks Vivek
On 07/24/14 at 09:43am, Vivek Goyal wrote:
On Tue, Jul 22, 2014 at 03:20:06PM +0800, WANG Chao wrote:
[..]
do_default_action() {
- wait_for_loginit
- echo "Kdump: Error Occured, doing default action"
Ho about following.
"Kdump: Executing default action $DEFAULT_ACTION"
This looks good to me.
I think error occurred is implied. And we should output an error message where actual error happened.
That's hard to implement. Because we don't propagate the error upwards when certain systemd unit fails.
But I wouldn't worry much about it. Because there would be messages for any failure on the console. And it's the same for our kdump.sh.
I had recommened similar message in RHEL6, I guess. Can you please look it up and try to keep message same.
It's hard to be exactly the same with RHEL6. Since RHEL6 uses the following output:
"XXX failed. Executing default action"
I think "Kdump: Executing default action $DEFAULT_ACTION" is good enough.
What do you think?
Thanks WANG Chao
Let us try our best to keep the messages consistent across all releases.
Thanks Vivek
On Fri, Jul 25, 2014 at 01:56:56PM +0800, WANG Chao wrote:
[..]
I had recommened similar message in RHEL6, I guess. Can you please look it up and try to keep message same.
It's hard to be exactly the same with RHEL6. Since RHEL6 uses the following output:
"XXX failed. Executing default action"
I think "Kdump: Executing default action $DEFAULT_ACTION" is good enough.
What do you think?
Ok, I am fine with it.
Thanks Vivek
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@redhat.com --- dracut-kdump-emergency.service | 30 ++++++++++++++++++++++++++++++ dracut-kdump-error-handler.sh | 10 ++++++++++ dracut-kdump.sh | 4 ---- dracut-module-setup.sh | 3 +++ kdump-lib-initramfs.sh | 34 ++++++++++++++++++++++++++++++---- kexec-tools.spec | 5 ++++- 6 files changed, 77 insertions(+), 9 deletions(-) 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..4434b9e --- /dev/null +++ b/dracut-kdump-emergency.service @@ -0,0 +1,30 @@ +# 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. + +[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-kdump.sh b/dracut-kdump.sh index a2bfa05..83c1e96 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -9,10 +9,6 @@ exec &> /dev/console . /lib/dracut-lib.sh . /lib/kdump-lib-initramfs.sh
-if [ -f "$initdir/lib/dracut/no-emergency-shell" ]; then - rm -f -- $initdir/lib/dracut/no-emergency-shell -fi - set -o pipefail DUMP_RETVAL=0
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 758420b..5d701e6 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -581,6 +581,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/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 9118b64..1517712 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -1,6 +1,5 @@ # These variables and functions are useful in 2nd kernel
-. /lib/dracut-lib.sh . /lib/kdump-lib.sh
KDUMP_PATH="/var/crash" @@ -23,6 +22,7 @@ NEWROOT="/sysroot" get_kdump_confs() { local config_opt config_val + local user_specified_cc
while read config_opt config_val; do @@ -34,6 +34,7 @@ get_kdump_confs() ;; core_collector) [ -n "$config_val" ] && CORE_COLLECTOR="$config_val" + user_specified_cc=yes ;; sshkey) if [ -f "$config_val" ]; then @@ -55,7 +56,7 @@ get_kdump_confs() default) case $config_val in shell) - DEFAULT_ACTION="_emergency_shell kdump" + DEFAULT_ACTION="kdump_emergency_shell" ;; reboot) DEFAULT_ACTION="do_umount; reboot -f" @@ -67,12 +68,19 @@ get_kdump_confs() DEFAULT_ACTION="do_umount; poweroff -f" ;; dump_to_rootfs) - DEFAULT_ACTION="dump_fs $NEWROOT" + DEFAULT_ACTION="dump_to_rootfs" ;; esac ;; esac done < $KDUMP_CONF + + if is_ssh_dump_target || is_raw_dump_target; then + if [ -z "$user_specified_cc" ]; then + CORE_COLLECTOR="$CORE_COLLECTOR -F" + fi + fi + }
# dump_fs <mount point| device> @@ -127,6 +135,24 @@ save_vmcore_dmesg_fs() { fi }
+dump_to_rootfs() +{ + + echo "Kdump: trying to bring up rootfs device" + systemctl start dracut-initqueue + echo "Kdump: waiting for rootfs mount, will timeout after 90 seconds" + systemctl start sysroot.mount + + dump_fs $NEWROOT +} + +kdump_emergency_shell() +{ + echo "PS1="kdump:\${PWD}# "" >/etc/profile + /bin/dracut-emergency + rm -f /etc/profile +} + do_umount() { umount -Rf $NEWROOT @@ -134,7 +160,7 @@ do_umount()
do_default_action() { - wait_for_loginit + echo "Kdump: Executing default action $DEFAULT_ACTION" eval $DEFAULT_ACTION }
diff --git a/kexec-tools.spec b/kexec-tools.spec index b55a7f1..91deade 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}}
This patch introduce a new kdump-capture.service which is used to run kdump.sh.
kdump-capture.service has OnFailure=emergency.target and OnFailureIsolate=yes set. When kdump.sh fails, the kdump emergency service will be triggered and enter the error handling path.
In 2nd kernel, the default target for systemd is initrd.target, so we put kdump-capture.service in initrd.target.wants/ and by that, system will start kdump-capture as part of the boot process.
kdump.sh used to run in dracut-pre-pivot hook. Now kdump-capture.service is placed after dracut-pre-pivot.service and other dependencies are all copied from dracut-pre-pivot.service. So the start point of kdump.sh will be almost the same as it used to be.
Signed-off-by: WANG Chao chaowang@redhat.com --- dracut-kdump-capture.service | 30 ++++++++++++++++++++++++++++++ dracut-kdump.sh | 5 ++--- dracut-module-setup.sh | 4 +++- kexec-tools.spec | 2 ++ 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 dracut-kdump-capture.service
diff --git a/dracut-kdump-capture.service b/dracut-kdump-capture.service new file mode 100644 index 0000000..57139c9 --- /dev/null +++ b/dracut-kdump-capture.service @@ -0,0 +1,30 @@ +# 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. + +[Unit] +Description=Kdump Vmcore Save Service +After=initrd.target initrd-parse-etc.service sysroot.mount +After=dracut-initqueue.service dracut-pre-mount.service dracut-mount.service dracut-pre-pivot.service +Before=initrd-cleanup.service +ConditionPathExists=/etc/initrd-release +OnFailure=emergency.target +OnFailureIsolate=yes + +[Service] +Environment=DRACUT_SYSTEMD=1 +Environment=NEWROOT=/sysroot +Type=oneshot +ExecStart=/bin/kdump.sh +StandardInput=null +StandardOutput=syslog +StandardError=syslog+console +KillMode=process +RemainAfterExit=yes + +# Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash +# terminates cleanly. +KillSignal=SIGHUP diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 1fe91ab..b9b09ac 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -174,8 +174,7 @@ fi get_host_ip if [ $? -ne 0 ]; then echo "kdump: get_host_ip exited with non-zero status!" - do_default_action - do_final_action + exit 1 fi
if [ -z "$DUMP_INSTRUCTION" ]; then @@ -197,7 +196,7 @@ if [ $? -ne 0 ]; then fi
if [ $DUMP_RETVAL -ne 0 ]; then - do_default_action + exit 1 fi
do_final_action diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 4799219..b58146c 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -553,9 +553,11 @@ install() { inst "/bin/cut" "/bin/cut" inst "/sbin/makedumpfile" "/sbin/makedumpfile" 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 "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump-lib-initramfs.sh" + inst "$moddir/kdump.sh" "/usr/bin/kdump.sh" + inst "$moddir/kdump-capture.service" "$systemdsystemunitdir/kdump-capture.service" + ln_r "$systemdsystemunitdir/kdump-capture.service" "$systemdsystemunitdir/initrd.target.wants/kdump-capture.service" 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" diff --git a/kexec-tools.spec b/kexec-tools.spec index b3081bb..55d1659 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -38,6 +38,7 @@ Source101: dracut-module-setup.sh Source102: dracut-monitor_dd_progress Source103: dracut-kdump-error-handler.sh Source104: dracut-kdump-emergency.service +Source105: dracut-kdump-capture.service
Requires(post): systemd-units Requires(preun): systemd-units @@ -214,6 +215,7 @@ cp %{SOURCE101} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpb 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}} +cp %{SOURCE105} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE105}} 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}}
On Tue, Jul 22, 2014 at 03:20:07PM +0800, WANG Chao wrote:
This patch introduce a new kdump-capture.service which is used to run kdump.sh.
kdump-capture.service has OnFailure=emergency.target and OnFailureIsolate=yes set. When kdump.sh fails, the kdump emergency service will be triggered and enter the error handling path.
In 2nd kernel, the default target for systemd is initrd.target, so we put kdump-capture.service in initrd.target.wants/ and by that, system will start kdump-capture as part of the boot process.
kdump.sh used to run in dracut-pre-pivot hook. Now kdump-capture.service is placed after dracut-pre-pivot.service and other dependencies are all copied from dracut-pre-pivot.service. So the start point of kdump.sh will be almost the same as it used to be.
Signed-off-by: WANG Chao chaowang@redhat.com
Looks good.
Acked-by: Vivek Goyal vgoyal@redhat.com
Thanks Vivek
dracut-kdump-capture.service | 30 ++++++++++++++++++++++++++++++ dracut-kdump.sh | 5 ++--- dracut-module-setup.sh | 4 +++- kexec-tools.spec | 2 ++ 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 dracut-kdump-capture.service
diff --git a/dracut-kdump-capture.service b/dracut-kdump-capture.service new file mode 100644 index 0000000..57139c9 --- /dev/null +++ b/dracut-kdump-capture.service @@ -0,0 +1,30 @@ +# 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.
+[Unit] +Description=Kdump Vmcore Save Service +After=initrd.target initrd-parse-etc.service sysroot.mount +After=dracut-initqueue.service dracut-pre-mount.service dracut-mount.service dracut-pre-pivot.service +Before=initrd-cleanup.service +ConditionPathExists=/etc/initrd-release +OnFailure=emergency.target +OnFailureIsolate=yes
+[Service] +Environment=DRACUT_SYSTEMD=1 +Environment=NEWROOT=/sysroot +Type=oneshot +ExecStart=/bin/kdump.sh +StandardInput=null +StandardOutput=syslog +StandardError=syslog+console +KillMode=process +RemainAfterExit=yes
+# Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash +# terminates cleanly. +KillSignal=SIGHUP diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 1fe91ab..b9b09ac 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -174,8 +174,7 @@ fi get_host_ip if [ $? -ne 0 ]; then echo "kdump: get_host_ip exited with non-zero status!"
- do_default_action
- do_final_action
- exit 1
fi
if [ -z "$DUMP_INSTRUCTION" ]; then @@ -197,7 +196,7 @@ if [ $? -ne 0 ]; then fi
if [ $DUMP_RETVAL -ne 0 ]; then
- do_default_action
- exit 1
fi
do_final_action diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 4799219..b58146c 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -553,9 +553,11 @@ install() { inst "/bin/cut" "/bin/cut" inst "/sbin/makedumpfile" "/sbin/makedumpfile" 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 "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump-lib-initramfs.sh"
- inst "$moddir/kdump.sh" "/usr/bin/kdump.sh"
- inst "$moddir/kdump-capture.service" "$systemdsystemunitdir/kdump-capture.service"
- ln_r "$systemdsystemunitdir/kdump-capture.service" "$systemdsystemunitdir/initrd.target.wants/kdump-capture.service" 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"
diff --git a/kexec-tools.spec b/kexec-tools.spec index b3081bb..55d1659 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -38,6 +38,7 @@ Source101: dracut-module-setup.sh Source102: dracut-monitor_dd_progress Source103: dracut-kdump-error-handler.sh Source104: dracut-kdump-emergency.service +Source105: dracut-kdump-capture.service
Requires(post): systemd-units Requires(preun): systemd-units @@ -214,6 +215,7 @@ cp %{SOURCE101} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpb 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}} +cp %{SOURCE105} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE105}} 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