All of lore.kernel.org
 help / color / mirror / Atom feed
From: Louis Bouchard <louis.bouchard@ubuntu.com>
To: kexec@lists.infradead.org
Subject: [PATCH 1/9] Add SSH remote dump collection mechanism
Date: Wed, 20 Aug 2014 13:11:12 +0200	[thread overview]
Message-ID: <1408533080-17838-2-git-send-email-louis.bouchard@ubuntu.com> (raw)
In-Reply-To: <1408533080-17838-1-git-send-email-louis.bouchard@ubuntu.com>

Make Error testing coherent to all sections
Add initial SSH connectivity verification to remote host
use ssh -i with explicit key location

On Ubuntu kdump-config runs as root with / as $HOME so it cannot
locate the .ssh directory. Tell the ssh commands where to find
it explicitely

Signed-off-by: Louis Bouchard <louis.bouchard@ubuntu.com>
---
 debian/kdump-config        | 79 +++++++++++++++++++++++++++++++++++++++++++++-
 debian/kdump-tools.default |  9 ++++++
 2 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/debian/kdump-config b/debian/kdump-config
index 2e6cad9..4e283ab 100755
--- a/debian/kdump-config
+++ b/debian/kdump-config
@@ -357,6 +357,79 @@ function kdump_save_core()
 	fi
 }
 
+function kdump_save_core_to_ssh()
+{
+	KDUMP_SSH_KEY="${SSH_KEY:=/root/.ssh/kdump_id_rsa}"
+	KDUMP_STAMP=`date +"%Y%m%d%H%M"`
+	KDUMP_REMOTE_HOST="$SSH"
+	KDUMP_STAMPDIR="$KDUMP_COREDIR/$KDUMP_STAMP"
+	KDUMP_CORETEMP="$KDUMP_STAMPDIR/dump-incomplete"
+	KDUMP_COREFILE="$KDUMP_STAMPDIR/dump.$KDUMP_STAMP"
+	KDUMP_TMPDMESG="/tmp/dmesg.$KDUMP_STAMP"
+	KDUMP_DMESGFILE="$KDUMP_STAMPDIR/dmesg.$KDUMP_STAMP"
+	ERROR=0
+
+	ssh -i $KDUMP_SSH_KEY $KDUMP_REMOTE_HOST mkdir -p $KDUMP_STAMPDIR
+	ERROR=$?
+	# If remote connections fails, no need to continue
+	if [ $ERROR -ne 0 ] ; then
+		log_failure_msg "$NAME: Unable to reach remote server $KDUMP_REMOTE_HOST. No reason to continue"
+		logger -t $NAME "Unable to reach remote server $KDUMP_REMOTE_HOST. No reason to continue"
+		return 1
+	fi
+
+	log_action_msg "sending makedumpfile $MAKEDUMP_ARGS $vmcore_file to $KDUMP_REMOTE_HOST : $KDUMP_CORETEMP"
+	makedumpfile $MAKEDUMP_ARGS $vmcore_file | ssh -i $KDUMP_SSH_KEY $KDUMP_REMOTE_HOST dd of=$KDUMP_CORETEMP
+	ERROR=$?
+	if [ $ERROR -ne 0 ] ; then
+		log_failure_msg "$NAME: makedumpfile failed, falling back to 'scp'"
+		logger -t $NAME "makedumpfile failed, falling back to 'scp'"
+		KDUMP_CORETEMP="$KDUMP_STAMPDIR/vmcore-incomplete"
+		KDUMP_COREFILE="$KDUMP_STAMPDIR/vmcore.$KDUMP_STAMP"
+		scp -i $KDUMP_SSH_KEY $vmcore_file $KDUMP_REMOTE_HOST:$KDUMP_CORETEMP
+		if [ $? -ne 0 ];then
+			log_failure_msg "$NAME: makedumpfile scp failed. The vmcore file will  not be available"
+			logger -t $NAME "makedumpfile scp failed. The vmcore file will  not be available"
+		else
+			ERROR=0
+		fi
+	else
+		ERROR=0
+	fi
+
+	# did we succeed?
+	if [ $ERROR -ne 0 ]; then
+		log_failure_msg "$NAME: failed to save vmcore in $KDUMP_REMOTE_HOST:$KDUMP_STAMPDIR"
+		logger -t $NAME "failed to save vmcore in $KDUMP_REMOTE_HOST:$KDUMP_STAMPDIR"
+	else
+		ssh -i $KDUMP_SSH_KEY $KDUMP_REMOTE_HOST mv $KDUMP_CORETEMP $KDUMP_COREFILE
+		log_success_msg "$NAME: saved vmcore in $KDUMP_REMOTE_HOST:$KDUMP_STAMPDIR"
+		logger -t $NAME "saved vmcore in $KDUMP_REMOTE_HOST:$KDUMP_STAMPDIR"
+	fi
+
+	log_action_msg "running makedumpfile --dump-dmesg $vmcore_file $KDUMP_TMPDMESG"
+	makedumpfile --dump-dmesg $vmcore_file $KDUMP_TMPDMESG
+	ERROR=$?
+	if [ $ERROR -ne 0 ] ; then
+		log_failure_msg "$NAME: makedumpfile --dump-dmesg failed. dmesg content will be unavailable"
+		logger -t $NAME "makedumpfile --dump-dmesg failed. dmesg content will be unavailable"
+	else
+		scp -i $KDUMP_SSH_KEY $KDUMP_TMPDMESG $KDUMP_REMOTE_HOST:$KDUMP_DMESGFILE
+		ERROR=$?
+	fi
+
+	# did we succeed?
+	if [ $ERROR == 0 ]; then
+		log_success_msg "$NAME: saved dmesg content in $KDUMP_REMOTE_HOST:$KDUMP_STAMPDIR"
+		logger -t $NAME "saved dmesg content in $KDUMP_REMOTE_HOST:$KDUMP_STAMPDIR"
+		return 0;
+	else
+		log_failure_msg "$NAME: failed to save dmesg content in $KDUMP_REMOTE_HOST:$KDUMP_STAMPDIR"
+		logger -t $NAME "failed to save dmesg content in $KDUMP_REMOTE_HOST:$KDUMP_STAMPDIR"
+		return 1;
+	fi
+}
+
 
 
 case "$1" in
@@ -390,7 +463,11 @@ case "$1" in
 	exit 0;
 	;;
   savecore)
-	kdump_save_core
+	if ! [ -z $SSH ] || ! [ -z $NFS ] || [ -z NFS4 ]];then
+		kdump_save_core_to_ssh
+	else
+		kdump_save_core
+	fi
 	exit $?
 	;;
   help|-h*|--h*)
diff --git a/debian/kdump-tools.default b/debian/kdump-tools.default
index 8d02da0..e5e3bec 100644
--- a/debian/kdump-tools.default
+++ b/debian/kdump-tools.default
@@ -63,3 +63,12 @@ KDUMP_COREDIR="/var/crash"
 
 # ---------------------------------------------------------------------------
 # Architecture specific Overrides:
+
+# ---------------------------------------------------------------------------
+# Remote dump facilities
+#
+# SSH="<user@server>"
+#
+# NFS="<nfs mount>"
+#
+# NFS4="<nfs mount>"
-- 
1.9.1


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  reply	other threads:[~2014-08-20 11:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-20 11:11 [PATCH 0/9] Remote kernel crash dump for Debian and Ubuntu Louis Bouchard
2014-08-20 11:11 ` Louis Bouchard [this message]
2014-08-20 11:11 ` [PATCH 2/9] Implement propagate to send ssh key file to remote server Louis Bouchard
2014-08-20 11:11 ` [PATCH 3/9] Add comments to default/kdump-tools to outline functionality Louis Bouchard
2014-08-20 11:11 ` [PATCH 4/9] Add a prefix to the timestamped directory Louis Bouchard
2014-08-20 11:11 ` [PATCH 5/9] Add remote dump information to kdump-config show Louis Bouchard
2014-08-20 11:11 ` [PATCH 6/9] Add NFS remote dump collection Louis Bouchard
2014-08-20 11:11 ` [PATCH 7/9] Add NFS info to kdump-config show Louis Bouchard
2014-08-20 11:11 ` [PATCH 8/9] Reformat of the kdump-tools file Louis Bouchard
2014-08-20 11:11 ` [PATCH 9/9] Add check to avoid SSH and NFS being set together Louis Bouchard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1408533080-17838-2-git-send-email-louis.bouchard@ubuntu.com \
    --to=louis.bouchard@ubuntu.com \
    --cc=kexec@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.