From 4e4a173698c61d2fffe7262a66099835b0bcdccc Mon Sep 17 00:00:00 2001 From: Dave Young Date: Thu, 14 Jun 2012 09:57:30 +0800 Subject: [PATCH] Add kdump_post and kdump_pre support Original patch is from Amerigo, but it has changed a lot: remove multi dump refreshed with latest git for the dump instruction function restructure fixed the behavior of do_kdump_pre, if kdump_pre fails it will reboot update the docs check the existance and executable of kdump_pre/post files, also check the timestamp of them for rebuilding. refresh patch, Address comments from vivek: s/hush/bash in docs fix the copy-paste error in kdump post error message s/reboot\/halt/reboot in kexec-kdump-howto.txt Signed-off-by: Dave Young Acked-by: Vivek Goyal --- dracut-kdump.sh | 34 ++++++++++++++++++++++++++++++++++ dracut-module-setup.sh | 3 +++ kdump.conf | 22 +++++++++++++++++++++- kdump.conf.5 | 32 +++++++++++++++++++++++++++++++- kdumpctl | 7 +++++-- kexec-kdump-howto.txt | 16 ++++++++++++++++ 6 files changed, 110 insertions(+), 4 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index df27227..2717820 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -15,6 +15,8 @@ DD_BLKSIZE=512 FINAL_ACTION="reboot -f" DUMP_RETVAL=0 conf_file="/etc/kdump.conf" +KDUMP_PRE="" +KDUMP_POST="" export PATH=$PATH:$KDUMP_SCRIPT_DIR @@ -32,6 +34,20 @@ do_default_action() $DEFAULT_ACTION } +do_kdump_pre() +{ + if [ -n "$KDUMP_PRE" ]; then + "$KDUMP_PRE" + fi +} + +do_kdump_post() +{ + if [ -n "$KDUMP_POST" ]; then + "$KDUMP_POST" "$1" + fi +} + add_dump_code() { DUMP_INSTRUCTION=$1 @@ -164,6 +180,12 @@ read_kdump_conf() SSH_KEY_LOCATION=$config_val fi ;; + kdump_pre) + KDUMP_PRE="$config_val" + ;; + kdump_post) + KDUMP_POST="$config_val" + ;; default) case $config_val in shell) @@ -218,8 +240,20 @@ if [ -z "$DUMP_INSTRUCTION" ]; then add_dump_code "dump_rootfs" fi +do_kdump_pre +if [ $? -ne 0 ]; then + echo "kdump_pre script exited with non-zero status!" + $FINAL_ACTION +fi + $DUMP_INSTRUCTION DUMP_RETVAL=$? + +do_kdump_post $DUMP_RETVAL +if [ $? -ne 0 ]; then + echo "kdump_post script exited with non-zero status!" +fi + if [ $DUMP_RETVAL -ne 0 ]; then do_default_action fi diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 1acefdb..ed8702e 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -156,6 +156,9 @@ kdump_install_conf() { net) kdump_install_net "$config_val" ;; + kdump_pre|kdump_post) + dracut_install $config_val + ;; esac done < /etc/kdump.conf diff --git a/kdump.conf b/kdump.conf index c3c613b..93de7ce 100644 --- a/kdump.conf +++ b/kdump.conf @@ -51,10 +51,28 @@ # For core_collector format details please refer to # kexec-kdump-howto.txt or kdump.conf manpage. # +# kdump_post +# - This directive allows you to run a specified +# executable just after the memory dump process +# terminates. The exit status from the dump process +# is fed to the kdump_post executable, which can be +# used to trigger different actions for success or +# failure. +# +# kdump_pre +# - works just like the kdump_post directive, but instead +# of running after the dump process, runs immediately +# before. Exit status of this binary is interpreted +# as follows: +# 0 - continue with dump process as usual +# non 0 - reboot the system +# # extra_bins # - This directive allows you to specify additional # binaries or shell scripts you'd like to include in -# your kdump initrd. +# your kdump initrd. Generally only useful in +# conjunction with a kdump_post binary or script that +# relies on other binaries or scripts. # # extra_modules # - This directive allows you to specify extra kernel @@ -92,6 +110,8 @@ path /var/crash #core_collector makedumpfile -c --message-level 1 -d 31 #core_collector scp +#kdump_post /var/crash/scripts/kdump-post.sh +#kdump_pre /var/crash/scripts/kdump-pre.sh #extra_bins /usr/bin/lftp #extra_modules gfs2 #default shell diff --git a/kdump.conf.5 b/kdump.conf.5 index 854d794..9715b97 100644 --- a/kdump.conf.5 +++ b/kdump.conf.5 @@ -89,11 +89,41 @@ ie. "makedumpfile -R vmcore < vmcore.flat" .RE +.B kdump_post +.RS +This directive allows you to run a specified +executable just after the memory dump process +terminates. The exit status from the dump process +is fed to the kdump_post executable, which can be +used to trigger different actions for success or +failure. +.PP +Note that scripts written for use with this +directive must use the /bin/bash interpreter +.RE + +.B kdump_pre +.RS +Works just like the kdump_post directive, but instead +of running after the dump process, runs immediately +before. Exit status of this binary is interpreted +as follows: +.PP +0 - continue with dump process as usual +.PP +non 0 - reboot the system +.PP +Note that scripts written for this directive must use +the /bin/bash interpreter +.RE + .B extra_bins .RS This directive allows you to specify additional binaries or shell scripts you'd like to include in -your kdump initrd. +your kdump initrd. Generally only useful in +conjunction with a kdump_post binary or script that +relies on other binaries or scripts. .RE .B extra_modules diff --git a/kdumpctl b/kdumpctl index a2587ab..e1c7f8c 100755 --- a/kdumpctl +++ b/kdumpctl @@ -101,8 +101,11 @@ function check_config() image_time=0 fi - - EXTRA_BINS=`grep ^extra_bins $KDUMP_CONFIG_FILE | cut -d\ -f2-` + EXTRA_BINS=`grep ^kdump_post $KDUMP_CONFIG_FILE | cut -d\ -f2` + CHECK_FILES=`grep ^kdump_pre $KDUMP_CONFIG_FILE | cut -d\ -f2` + EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" + CHECK_FILES=`grep ^extra_bins $KDUMP_CONFIG_FILE | cut -d\ -f2-` + EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" files="$KDUMP_CONFIG_FILE $kdump_kernel $EXTRA_BINS" check_exist "$files" && check_executable "$EXTRA_BINS" diff --git a/kexec-kdump-howto.txt b/kexec-kdump-howto.txt index 3fa4b0a..c3d0b28 100644 --- a/kexec-kdump-howto.txt +++ b/kexec-kdump-howto.txt @@ -403,11 +403,27 @@ example, 'path /data/coredumps' would lead to vmcore files being written to that the path option is ingnored if your kdump configuration results in the core being saved from the initscripts in the root filesystem. +Kdump Post-Capture Executable + +It is possible to specify a custom script or binary you wish to run following +an attempt to capture a vmcore. The executable is passed an exit code from +the capture process, which can be used to trigger different actions from +within your post-capture executable. + +Kdump Pre-Capture Executable + +It is possible to specify a custom script or binary you wish to run before +capturing a vmcore. Exit status of this binary is interpreted: +0 - continue with dump process as usual +non 0 - reboot the system + Extra Binaries If you have specific binaries or scripts you want to have made available within your kdump initrd, you can specify them by their full path, and they will be included in your kdump initrd, along with all dependent libraries. +This may be particularly useful for those running post-capture scripts that +rely on other binaries. Extra Modules