diff --git a/Makefile b/Makefile index 56e019c7..dcf3e69b 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,7 @@ install: dracut-modules kdump-conf kdump-sysconfig manpages mkdir -p $(DESTDIR)$(pkglibdir)/dracut.conf.d mkdir -p -m755 $(DESTDIR)$(sysconfdir)/kdump/pre.d mkdir -p -m755 $(DESTDIR)$(sysconfdir)/kdump/post.d + mkdir -p -m755 $(DESTDIR)$(sysconfdir)/kdump/emergency.d mkdir -p -m755 $(DESTDIR)$(localstatedir)/crash mkdir -p -m755 $(DESTDIR)$(udevrulesdir) mkdir -p -m755 $(DESTDIR)$(sharedstatedir)/kdump diff --git a/dracut/99kdumpbase/kdump.sh b/dracut/99kdumpbase/kdump.sh index 5155453c..3e6baf74 100755 --- a/dracut/99kdumpbase/kdump.sh +++ b/dracut/99kdumpbase/kdump.sh @@ -33,6 +33,7 @@ DD_BLKSIZE=512 FINAL_ACTION="systemctl reboot -f" KDUMP_PRE="" KDUMP_POST="" +KDUMP_EMERGENCY="" NEWROOT="/sysroot" OPALCORE="/sys/firmware/opal/mpipl/core" KDUMP_CONF_PARSED="/tmp/kdump.conf.$$" @@ -66,6 +67,9 @@ get_kdump_confs() { kdump_post) KDUMP_POST="$config_val" ;; + kdump_emergency) + KDUMP_EMERGENCY="$config_val" + ;; fence_kdump_args) FENCE_KDUMP_ARGS="$config_val" ;; @@ -374,6 +378,25 @@ do_kdump_post() { fi } +do_kdump_emergency() { + if [ -d /etc/kdump/emergency.d ]; then + for file in /etc/kdump/emergency.d/*; do + "$file" + _ret=$? + if [ $_ret -ne 0 ]; then + derror "$file exited with $_ret status" + fi + done + fi + + if [ -n "$KDUMP_EMERGENCY" ]; then + "$KDUMP_EMERGENCY" + _ret=$? + if [ $_ret -ne 0 ]; then + derror "$KDUMP_EMERGENCY exited with $_ret status" + fi + fi +} # $1: block target, eg. /dev/sda dump_raw() { [ -b "$1" ] || return 1 @@ -641,6 +664,7 @@ kdump_test_init() { if [ "$1" = "--error-handler" ]; then get_kdump_confs + do_kdump_emergency do_failure_action save_log do_final_action diff --git a/dracut/99kdumpbase/module-setup.sh b/dracut/99kdumpbase/module-setup.sh index 5a580ce0..f0526219 100755 --- a/dracut/99kdumpbase/module-setup.sh +++ b/dracut/99kdumpbase/module-setup.sh @@ -660,7 +660,7 @@ kdump_install_net() { fi } -# install etc/kdump/pre.d and /etc/kdump/post.d +# install etc/kdump/pre.d and /etc/kdump/post.d /etc/kdump/emergency.d kdump_install_pre_post_conf() { if [[ -d /etc/kdump/pre.d ]]; then for file in /etc/kdump/pre.d/*; do @@ -681,6 +681,16 @@ kdump_install_pre_post_conf() { fi done fi + + if [[ -d /etc/kdump/emergency.d ]]; then + for file in /etc/kdump/emergency.d/*; do + if [[ -x $file ]]; then + dracut_install "$file" + elif [[ $file != "/etc/kdump/emergency.d/*" ]]; then + echo "$file is not executable" + fi + done + fi } default_dump_target_install_conf() { @@ -743,7 +753,7 @@ kdump_install_conf() { kdump_collect_netif_usage "$(get_dracut_args_target "$_val")" fi ;; - kdump_pre | kdump_post | extra_bins) + kdump_pre | kdump_post | kdump_emergency | extra_bins) # shellcheck disable=SC2086 dracut_install $_val ;; diff --git a/gen-kdump-conf.sh b/gen-kdump-conf.sh index 6581eb55..94159cc0 100755 --- a/gen-kdump-conf.sh +++ b/gen-kdump-conf.sh @@ -90,6 +90,14 @@ generate() # For core_collector format details, you can refer to # kexec-kdump-howto.txt or kdump.conf manpage. # +# kdump_emergency +# - This directive allows you to run a specified executable +# in emergency mode within the kdump capture kernel, +# prior to the dump process. +# All files under /etc/kdump/emergency.d are collectively sorted +# and executed in lexical order, before binary or script +# specified kdump_emergency parameter is executed. +# # kdump_post # - This directive allows you to run a executable binary # or script after the vmcore dump process terminates. diff --git a/kdump-utils.spec b/kdump-utils.spec index 2bfb2171..41a3939d 100644 --- a/kdump-utils.spec +++ b/kdump-utils.spec @@ -102,6 +102,7 @@ fi %dir %{_sysconfdir}/kdump %dir %{_sysconfdir}/kdump/pre.d %dir %{_sysconfdir}/kdump/post.d +%dir %{_sysconfdir}/kdump/emergency.d %dir %{_sharedstatedir}/kdump %{_mandir}/man8/kdumpctl.8* %{_mandir}/man8/mkdumprd.8* diff --git a/kdump.conf.5 b/kdump.conf.5 index 6b4e1815..8cf734a7 100644 --- a/kdump.conf.5 +++ b/kdump.conf.5 @@ -130,6 +130,23 @@ than the system's RAM. .RE +.B kdump_emergency +.RS +This directive allows you to run a specified executable +in emergency mode within the kdump capture kernel, +prior to the dump process. +.PP +All files under /etc/kdump/emergency.d are collectively sorted +and executed in lexical order, before binary or script +specified kdump_emergency parameter is executed. +.PP +Note that scripts written for use with this directive must use the /bin/bash +interpreter. And since these scripts run in kdump enviroment, the reference to +the storage or network device in the scripts should adhere to the section +'Supported dump target types and requirements' in kexec-kdump-howto.txt. + +.RE + .B kdump_post .RS This directive allows you to run a specified executable diff --git a/kdumpctl b/kdumpctl index dd617f60..bbe3db54 100755 --- a/kdumpctl +++ b/kdumpctl @@ -368,7 +368,7 @@ parse_config() dwarn "Please update $KDUMP_CONFIG_FILE to use option 'failure_action' instead." _set_config failure_action "$config_val" || return 1 ;; - path | core_collector | kdump_post | kdump_pre | extra_bins | extra_modules | failure_action | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes | auto_reset_crashkernel) ;; + path | core_collector | kdump_post | kdump_pre | kdump_emergency | extra_bins | extra_modules | failure_action | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes | auto_reset_crashkernel) ;; net | options | link_delay | disk_timeout | debug_mem_level | blacklist) derror "Deprecated kdump config option: $config_opt. Refer to kdump.conf manpage for alternatives." @@ -461,9 +461,6 @@ check_files_modified() #also rebuild when Pacemaker cluster conf is changed and fence kdump is enabled. modified_files=$(get_pcs_cluster_modified_files "$image_time") - EXTRA_BINS=${OPT[kdump_post]} - CHECK_FILES=${OPT[kdump_pre]} - HOOKS="/etc/kdump/post.d/ /etc/kdump/pre.d/" if [[ -d /etc/kdump/post.d ]]; then for file in /etc/kdump/post.d/*; do if [[ -x $file ]]; then @@ -478,13 +475,18 @@ check_files_modified() fi done fi - HOOKS="$HOOKS $POST_FILES $PRE_FILES" + if [[ -d /etc/kdump/emergency.d ]]; then + for file in /etc/kdump/emergency.d/*; do + if [[ -x $file ]]; then + EMERGENCY_FILES="$EMERGENCY_FILES $file" + fi + done + fi + HOOKS="$POST_FILES $PRE_FILES $EMERGENCY_FILES" CORE_COLLECTOR=$(echo "${OPT[core_collector]}" | awk '{print $1}') CORE_COLLECTOR=$(type -P "$CORE_COLLECTOR") # POST_FILES and PRE_FILES are already checked against executable, need not to check again. - EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" - CHECK_FILES=${OPT[extra_bins]} - EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" + EXTRA_BINS="${OPT[kdump_post]} ${OPT[kdump_pre]} ${OPT[kdump_emergency]} ${OPT[extra_bins]}" files="$KDUMP_CONFIG_FILE $KDUMP_KERNEL $EXTRA_BINS $CORE_COLLECTOR" [[ -e /etc/fstab ]] && files="$files /etc/fstab" diff --git a/kexec-kdump-howto.txt b/kexec-kdump-howto.txt index 5d205a5c..628b7c94 100644 --- a/kexec-kdump-howto.txt +++ b/kexec-kdump-howto.txt @@ -618,6 +618,20 @@ level in the above KDUMP_COMMANDLINE_APPEND. Logging levels: no logging(0), error(1), warn(2), info(3), debug(4) +Kdump Emergency Executable +-------------------------- + +It is possible to specify a custom script or binary you wish to run in +emergency mode prior to the dump process. From the error handler launched +in emergency mode within the kdump capture kernel, you can trigger different +actions from within your specified executables. +If /etc/kdump/emergency.d directory exist, all files in the directory are +collectively sorted and executed in lexical order, before binary or script +specified using kdump_emergency option is executed. + +In these scripts, the reference to the storage or network device should adhere +to the section 'Supported dump target types and requirements' + Kdump Post-Capture Executable ----------------------------- @@ -625,7 +639,7 @@ 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. -If /etc/kdump/post.d directory exist, All files in the directory are +If /etc/kdump/post.d directory exist, all files in the directory are collectively sorted and executed in lexical order, before binary or script specified kdump_post parameter is executed.