[kexec-tools/f16] mkdumprd: use shutdown module of dracut to handle reboot/shutdown/halt.

Cong Wang wangcong at fedoraproject.org
Thu Jul 28 14:53:13 UTC 2011


commit 108f6ac2cc6988fd2516ec5f74078a73ccb5dc9e
Author: Amerigo Wang <amwang at redhat.com>
Date:   Thu Jul 28 22:50:43 2011 +0800

    mkdumprd: use shutdown module of dracut to handle reboot/shutdown/halt.

 kdump_dracut_modules/99kdumpbase/install          |    3 +-
 kdump_dracut_modules/99kdumpbase/kdump-lib.sh     |   48 ----------
 kdump_dracut_modules/99kdumpbase/kdump.sh         |  105 +++++++++++++++++++++
 kdump_dracut_modules/99kdumpbase/kdump_localfs.sh |   18 ----
 kexec-tools.spec                                  |    7 +-
 mkdumprd                                          |   14 ++--
 sources                                           |    3 +
 7 files changed, 121 insertions(+), 77 deletions(-)
---
diff --git a/kdump_dracut_modules/99kdumpbase/install b/kdump_dracut_modules/99kdumpbase/install
index c237329..6e22aa9 100755
--- a/kdump_dracut_modules/99kdumpbase/install
+++ b/kdump_dracut_modules/99kdumpbase/install
@@ -5,6 +5,5 @@ inst "/bin/sync" "/bin/sync"
 inst "/usr/bin/reboot" "/bin/reboot"
 inst "/sbin/makedumpfile" "/sbin/makedumpfile"
 inst "/etc/kdump.conf" "/etc/kdump.conf"
-inst "$moddir/kdump-lib.sh" "/lib/kdump-lib.sh"
-inst_hook pre-pivot 01 "$moddir/kdump_localfs.sh"
+inst_hook pre-pivot 01 "$moddir/kdump.sh"
 
diff --git a/kdump_dracut_modules/99kdumpbase/kdump.sh b/kdump_dracut_modules/99kdumpbase/kdump.sh
new file mode 100755
index 0000000..22d475f
--- /dev/null
+++ b/kdump_dracut_modules/99kdumpbase/kdump.sh
@@ -0,0 +1,105 @@
+#!/bin/sh
+
+. /lib/dracut-lib.sh
+
+set -x
+KDUMP_PATH="/var/crash"
+CORE_COLLECTOR="makedumpfile -d 31 -c"
+DEFAULT_ACTION="reboot -f"
+DATEDIR=`date +%d.%m.%y-%T`
+DUMP_INSTRUCTION=""
+
+do_default_action()
+{
+    wait_for_loginit
+    $DEFAULT_ACTION
+}
+
+add_dump_instruction()
+{
+    if [ -z "$DUMP_INSTRUCTION" ]
+    then
+        DUMP_INSTRUCTION="$1"
+    else
+        DUMP_INSTRUCTION="$DUMP_INSTRUCTION && $1"
+    fi
+}
+
+dump_rootfs()
+{
+    mount -o remount,rw $NEWROOT/ || return 1
+    mkdir -p $NEWROOT/$KDUMP_PATH/$DATEDIR
+    $CORE_COLLECTOR /proc/vmcore $NEWROOT/$KDUMP_PATH/$DATEDIR/vmcore || return 1
+    sync
+    return 0
+}
+
+dump_nfs()
+{
+    mount -o nolock -o tcp -t nfs $1 $NEWROOT/mnt/
+    mkdir -p $NEWROOT/mnt/$KDUMP_PATH/$DATEDIR || return 1
+    $CORE_COLLECTOR /proc/vmcore $NEWROOT/mnt/$KDUMP_PATH/$DATEDIR/vmcore || return 1
+    umount $NEWROOT/mnt/ || return 1
+    return 0
+}
+
+dump_ssh()
+{
+    ssh -q -o BatchMode=yes -o StrictHostKeyChecking=yes $1 mkdir -p $KDUMP_PATH/$DATEDIR || return 1
+    scp -q -o BatchMode=yes -o StrictHostKeyChecking=yes /proc/vmcore "$1:$KDUMP_PATH/$DATEDIR"  || return 1
+    return 0
+}
+
+read_kdump_conf()
+{
+    local conf_file="/etc/kdump.conf"
+    if [ -f "$conf_file" ]; then
+        while read config_opt config_val;
+        do
+	    case "$config_opt" in
+	    path)
+                KDUMP_PATH="$config_val"
+	        ;;
+            core_collector)
+		CORE_COLLECTOR="$config_val"
+                ;;
+            net)
+                if [ -n "$(echo $config_val | grep @)" ]
+                then
+                    add_dump_instruction "dump_ssh $config_val || do_default_action"
+                else
+                    add_dump_instruction "dump_nfs $config_val || do_default_action"
+                fi
+                ;;
+            default)
+                case $config_val in
+                    shell)
+                        DEFAULT_ACTION="sh -i -l"
+                        ;;
+                    reboot)
+                        DEFAULT_ACTION="reboot -f"
+                        ;;
+                    halt)
+                        DEFAULT_ACTION="halt -f"
+                        ;;
+                    poweroff)
+                        DEFAULT_ACTION="poweroff -f"
+                        ;;
+                esac
+	        ;;
+	    esac
+        done < $conf_file
+    fi
+}
+
+read_kdump_conf
+
+if [ -n "$DUMP_INSTRUCTION" ]
+then
+    eval "$DUMP_INSTRUCTION"
+else
+    dump_rootfs
+    do_default_action
+fi
+
+
diff --git a/kexec-tools.spec b/kexec-tools.spec
index 170331a..1e5d83b 100644
--- a/kexec-tools.spec
+++ b/kexec-tools.spec
@@ -1,6 +1,6 @@
 Name: kexec-tools
 Version: 2.0.2
-Release: 14%{?dist}
+Release: 15%{?dist}
 License: GPLv2
 Group: Applications/System
 Summary: The kexec/kdump userspace component.
@@ -169,7 +169,7 @@ mkdir -p -m755 $RPM_BUILD_ROOT/etc/kdump-adv-conf
 tar -C $RPM_BUILD_ROOT/etc/kdump-adv-conf -jxvf %{SOURCE100}
 chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/check
 chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/install
-chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/kdump_localfs.sh
+chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/kdump.sh
 
 
 #and move the custom dracut modules to the dracut directory
@@ -281,6 +281,9 @@ done
 
 
 %changelog
+* Wed Jul 28 2011 Cong Wang <xiyou.wangcong at gmail.com> - 2.0.2-15
+- Use shutdown module of dracut to handle reboot/shutdown/halt.
+
 * Wed Jul 27 2011 Cong Wang <xiyou.wangcong at gmail.com> - 2.0.2-14
 - Wait for loginit.
 
diff --git a/mkdumprd b/mkdumprd
index 6ba9d9f..9a1edcc 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -10,7 +10,7 @@ export IN_KDUMP=1
 
 conf_file="/etc/kdump.conf"
 extra_modules=""
-dracut_args="-H -o i18n -o plymouth"
+dracut_args="-H -o i18n -o plymouth --add shutdown -c /dev/null"
 
 add_dracut_arg() {
     dracut_args="$dracut_args $*"
@@ -38,12 +38,12 @@ done
 
 # $1 target device
 # $2 if this is a raw dump
-dump_local() {
+check_local() {
     return
 }
 
 # $1 remote target
-dump_remote() {
+check_remote() {
     return
 }
 
@@ -55,14 +55,14 @@ if [ -n "$conf_file" ]; then
             extra_modules="$extra_modules $config_val"
             ;;
         ext[234]|xfs|btrfs|minix)
-            dump_local "$config_val" 0
+            check_local "$config_val" 0
             ;;
         raw)
-            dump_local "$config_val" 1
+            check_local "$config_val" 1
             ;;
         net)
             add_dracut_arg "--add network"
-            dump_remote "$config_val"
+            check_remote "$config_val"
             ;;
         core_collector)
             add_dracut_arg "-I ${config_val% *}"
@@ -75,7 +75,6 @@ if [ -n "$conf_file" ]; then
             then
                 continue
             fi
-            dump_local ""
             ;;
         esac
     done < $conf_file
@@ -87,4 +86,5 @@ then
 fi
 
 dracut $dracut_args "$@"
+exit $?
 
diff --git a/sources b/sources
index 1950ce3..afce193 100644
--- a/sources
+++ b/sources
@@ -9,3 +9,6 @@ d872bdde29eb036cd59e7b71c148fca6  dracut-files.tbz2
 7d1516ae8af7000cec149b9409f9b859  dracut-files.tbz2
 ea7a345cbaa0d3d9a9dbd46631155550  dracut-files.tbz2
 d220ff5e4b07c34701d9a1fe991ef2e4  dracut-files.tbz2
+1548d83e2713660c4cbd2c284fdad25b  dracut-files.tbz2
+adea715e719a4c460c41d8134aafa95b  dracut-files.tbz2
+c7e9dd35476cb33f09f22037f6c16982  dracut-files.tbz2


More information about the scm-commits mailing list