Hi,
Attached is a newer version of the FTP support patch.
This version uses FTP={HOSTNAME}:{PATH} as configuration option instead
of FTP={HOSTNAME} and abusing KDUMP_COREDIR as path. It also shows all
configured FTP options in kdump_show().
--
Benjamin Drung
System Developer
Debian & Ubuntu Developer
ProfitBricks GmbH
Greifswalder Str. 207
D - 10405 Berlin
Email: [email protected]
URL: http://www.profitbricks.com
Sitz der Gesellschaft: Berlin.
Registergericht: Amtsgericht Charlottenburg, HRB 125506B.
Geschäftsführer: Andreas Gauger, Achim Weiss.From 13e985e4bd2c49c6af1f352d67820e277da886d8 Mon Sep 17 00:00:00 2001
From: Benjamin Drung <[email protected]>
Date: Tue, 7 Mar 2017 11:35:29 +0100
Subject: [PATCH] Add support for FTP uploads
Closes: #856957
---
debian/kdump-config | 97 ++++++++++++++++++++++++++++++++++++++++++++--
debian/kdump-tools.default | 12 ++++++
2 files changed, 106 insertions(+), 3 deletions(-)
diff --git a/debian/kdump-config b/debian/kdump-config
index ba79bc8..517c43e 100755
--- a/debian/kdump-config
+++ b/debian/kdump-config
@@ -133,8 +133,20 @@ function kdump_show()
echo "NFS_TIMEO: ${NFS_TIMEO:=600}"
echo "NFS_RETRANS ${NFS_RETRANS:=3}"
fi
+ if [ -n "$FTP" ]; then
+ echo "FTP: $FTP"
+ if [ -n "$FTP_USER" ]; then
+ echo "FTP_USER: $FTP_USER"
+ fi
+ if [ -n "$FTP_PASSWORD" ]; then
+ echo "FTP_PASSWORD: is set"
+ fi
+ if [ -n "$FTP_PORT" ]; then
+ echo "FTP_PORT: $FTP_PORT"
+ fi
+ fi
- if [ -n "$SSH" ] || [ -n "$NFS" ]; then
+ if [ -n "$SSH" ] || [ -n "$NFS" ] || [ -n "$FTP" ]; then
HOSTTAG="${HOSTTAG:=ip}"
echo "HOSTTAG: $HOSTTAG"
fi
@@ -275,6 +287,14 @@ function check_fadump_support()
log_failure_msg "\$SSH and \$NFS cannot be defined concurrently"
[ ! $DRY_RUN ] && exit 1;
fi
+ if [ -n "$FTP" ] && [ -n "$SSH" ];then
+ log_failure_msg "\$FTP and \$SSH cannot be defined concurrently"
+ [ ! $DRY_RUN ] && exit 1;
+ fi
+ if [ -n "$FTP" ] && [ -n "$NFS" ];then
+ log_failure_msg "\$FTP and \$NFS cannot be defined concurrently"
+ [ ! $DRY_RUN ] && exit 1;
+ fi
}
# check_kdump_support: Other miscellaneous checks go here:
@@ -596,7 +616,7 @@ function define_stampdir()
STAMP=$1
HOSTTAG="${HOSTTAG:=ip}"
- if [ -z "$SSH" ] && [ -z "$NFS" ]; then
+ if [ -z "$SSH" ] && [ -z "$NFS" ] && [ -z "$FTP" ]; then
echo "$KDUMP_COREDIR/$STAMP"
elif [ "$HOSTTAG" = "hostname" ];then
echo "$KDUMP_COREDIR/$(hostname)-$STAMP"
@@ -747,6 +767,75 @@ function kdump_save_core()
return $ERROR
}
+kdump_save_core_to_ftp()
+{
+ KDUMP_REMOTE_HOST="${FTP%%:*}"
+ KDUMP_COREDIR="${FTP#*:}"
+ if [ "$KDUMP_COREDIR" = "$FTP" ]; then
+ # No colon in FTP specified. Assuming / as path
+ KDUMP_COREDIR="/"
+ fi
+
+ KDUMP_STAMP=`date +"%Y%m%d%H%M"`
+ KDUMP_STAMPDIR=$(define_stampdir "")
+
+ KDUMP_COREFILE="${KDUMP_STAMPDIR}dump.$KDUMP_STAMP"
+ KDUMP_TMPDMESG="/tmp/dmesg.$KDUMP_STAMP"
+ KDUMP_DMESGFILE="${KDUMP_STAMPDIR}dmesg.$KDUMP_STAMP"
+ ERROR=0
+
+ FTPPUT_ARGS=""
+ if [ -n "$FTP_USER" ]; then
+ FTPPUT_ARGS="$FTPPUT_ARGS -u $FTP_USER"
+ fi
+ if [ -n "$FTP_PASSWORD" ]; then
+ FTPPUT_ARGS="$FTPPUT_ARGS -p $FTP_PASSWORD"
+ fi
+ if [ -n "$FTP_PORT" ]; then
+ FTPPUT_ARGS="$FTPPUT_ARGS -P $FTP_PORT"
+ fi
+
+ # Add '-F' [flatten] to MAKEDUMP_ARGS, if not there:
+ [ "${MAKEDUMP_ARGS#-F*}" != "${MAKEDUMP_ARGS}" ] || MAKEDUMP_ARGS="${MAKEDUMP_ARGS} -F"
+ log_action_msg "sending makedumpfile $MAKEDUMP_ARGS $vmcore_file via FTP to $KDUMP_REMOTE_HOST:$KDUMP_COREFILE"
+ makedumpfile $MAKEDUMP_ARGS $vmcore_file | busybox ftpput $FTPPUT_ARGS $KDUMP_REMOTE_HOST $KDUMP_COREFILE -
+ ERROR=$?
+
+ # did we succeed?
+ if [ $ERROR -ne 0 ]; then
+ log_failure_msg "$NAME: failed to save vmcore via FTP in $KDUMP_REMOTE_HOST:$KDUMP_COREFILE"
+ logger -t $NAME "failed to save vmcore via FTP in $KDUMP_REMOTE_HOST:$KDUMP_COREFILE"
+ else
+ log_success_msg "$NAME: saved vmcore via FTP in $KDUMP_REMOTE_HOST:$KDUMP_COREFILE"
+ logger -t $NAME "saved vmcore via FTP in $KDUMP_REMOTE_HOST:$KDUMP_COREFILE"
+ fi
+
+ # dump the dmesg buffer
+ if [ "$KDUMP_DUMP_DMESG" -eq 1 ] ; then
+ 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
+ busybox ftpput $FTPPUT_ARGS $KDUMP_REMOTE_HOST $KDUMP_DMESGFILE $KDUMP_TMPDMESG
+ ERROR=$?
+ fi
+
+ # did we succeed?
+ if [ $ERROR == 0 ]; then
+ log_success_msg "$NAME: saved dmesg content via FTP in $KDUMP_REMOTE_HOST:$KDUMP_DMESGFILE"
+ logger -t $NAME "saved dmesg content via FTP in $KDUMP_REMOTE_HOST:$KDUMP_DMESGFILE"
+ else
+ log_failure_msg "$NAME: failed to save dmesg content via FTP in $KDUMP_REMOTE_HOST:$KDUMP_DMESGFILE"
+ logger -t $NAME "failed to save dmesg content via FTP in $KDUMP_REMOTE_HOST:$KDUMP_DMESGFILE"
+ fi
+ fi
+
+ return $ERROR
+}
+
function kdump_save_core_to_ssh()
{
KDUMP_SSH_KEY="${SSH_KEY:=/root/.ssh/kdump_id_rsa}"
@@ -930,7 +1019,9 @@ case "$1" in
exit 0;
;;
savecore)
- if ! [ -z $SSH ];then
+ if [ -n "$FTP" ];then
+ kdump_save_core_to_ftp
+ elif ! [ -z $SSH ];then
kdump_save_core_to_ssh
else
kdump_save_core
diff --git a/debian/kdump-tools.default b/debian/kdump-tools.default
index c4d2659..591fab5 100644
--- a/debian/kdump-tools.default
+++ b/debian/kdump-tools.default
@@ -88,6 +88,13 @@ KDUMP_COREDIR="/var/crash"
# (e.g. remote:/var/crash)
# NFS_TIMEO - Timeout before NFS retries a request. See man nfs(5) for details.
# NFS_RETRANS - Number of times NFS client retries a request. See man nfs(5) for details.
+# FTP - Hostname and path of the FTP server configured to receive the crash dump.
+# The syntax must be {HOSTNAME}:{PATH}. When only {HOSTNAME} is specified,
+# / will be used as path.
+# FTP_USER - FTP username. A anonomous upload will be used if not set.
+# FTP_PASSWORD - password for the FTP user
+# FTP_PORT=21 - FTP port. Port 21 will be used by default.
+#
# SSH="<user at server>"
#
# SSH_KEY="<path>"
@@ -99,3 +106,8 @@ KDUMP_COREDIR="/var/crash"
# NFS_TIMEO="600"
#
# NFS_RETRANS="3"
+#
+#FTP="<server>:<path>"
+#FTP_USER=""
+#FTP_PASSWORD=""
+#FTP_PORT=21
--
2.9.3