From 8b64cb8fc57579bce743ac1e40e7e17d0abca4b4 Mon Sep 17 00:00:00 2001 From: Stepan Blyshchak Date: Fri, 11 Dec 2020 15:55:19 +0200 Subject: [PATCH 1/2] [generate_dump] allow to extend dump with plugin scripts. Plugins scripts are placed at /usr/bin/debug-dump/ and the output of these scripts will be gzipped and placed under dump archive in dump/.gz Signed-off-by: Stepan Blyshchak --- scripts/generate_dump | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/generate_dump b/scripts/generate_dump index edbd638e16..e45938d9e4 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -32,6 +32,8 @@ TARFILE=$DUMPDIR/$BASE.tar LOGDIR=$DUMPDIR/$BASE/dump NUM_ASICS=1 +PLUGIN_SCRIPTS="$(find /usr/bin/debug-dump -type f)" + ############################################################################### # Runs a comamnd and saves its output to the incrementally built tar. # Globals: @@ -722,6 +724,10 @@ main() { save_cmd "docker ps -a" "docker.ps" save_cmd "docker top pmon" "docker.pmon" + for plugin_script in $PLUGIN_SCRIPTS; do + save_cmd "bash $plugin_script" "$(basename $plugin_script)" true + done + save_saidump local asic="$(/usr/local/bin/sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)" From 94c270179cb504526f20dcba732f733daa92ad7a Mon Sep 17 00:00:00 2001 From: Stepan Blyshchak Date: Mon, 25 Jan 2021 15:24:56 +0200 Subject: [PATCH 2/2] [generate_dump] enhance plugin handling Signed-off-by: Stepan Blyshchak --- scripts/generate_dump | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/scripts/generate_dump b/scripts/generate_dump index b40f766521..854f86ed23 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -32,6 +32,7 @@ DUMPDIR=/var/dump TARDIR=$DUMPDIR/$BASE TARFILE=$DUMPDIR/$BASE.tar LOGDIR=$DUMPDIR/$BASE/dump +PLUGINS_DIR=/usr/local/bin/debug-dump NUM_ASICS=1 HOME=${HOME:-/root} USER=${USER:-root} @@ -121,8 +122,6 @@ save_bcmcmd_all_ns() { fi } -PLUGIN_SCRIPTS="$(find /usr/bin/debug-dump -type f)" - ############################################################################### # Runs a comamnd and saves its output to the incrementally built tar. # Command gets timedout if it runs for more than TIMEOUT_MIN minutes. @@ -140,6 +139,7 @@ PLUGIN_SCRIPTS="$(find /usr/bin/debug-dump -type f)" # cmd: The command to run. Make sure that arguments with spaces have quotes # filename: the filename to save the output as in $BASE/dump # do_gzip: (OPTIONAL) true or false. Should the output be gzipped +# save_stderr: (OPTIONAL) true or false. Should the stderr output be saved # Returns: # None ############################################################################### @@ -150,10 +150,17 @@ save_cmd() { local filename=$2 local filepath="${LOGDIR}/$filename" local do_gzip=${3:-false} + local save_stderr=${4:-true} local tarpath="${BASE}/dump/$filename" local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m" + local redirect="&>" [ ! -d $LOGDIR ] && $MKDIR $V -p $LOGDIR + if ! $save_stderr + then + redirect=">" + fi + # eval required here to re-evaluate the $cmd properly at runtime # This is required if $cmd has quoted strings that should be bunched # as one argument, e.g. vtysh -c "COMMAND HERE" needs to have @@ -173,9 +180,9 @@ save_cmd() { fi else if $NOOP; then - echo "${timeout_cmd} $cmd &> '$filepath'" + echo "${timeout_cmd} $cmd $redirect '$filepath'" else - eval "${timeout_cmd} $cmd" &> "$filepath" + eval "${timeout_cmd} $cmd" "$redirect" "$filepath" if [ $? -ne 0 ]; then echo "Command: $cmd timedout after ${TIMEOUT_MIN} minutes." fi @@ -304,7 +311,7 @@ save_bridge() { } ############################################################################### -# Dump the bridge L2 information +# Dump the bridge L2 information # Globals: # None # Arguments: @@ -511,8 +518,8 @@ save_proc() { ############################################################################### # Dumps all fields and values from given Redis DB. # Arguments: -# DB name: DB name -# Filename: Destination filename, if not given then filename would be DB name +# DB name: DB name +# Filename: Destination filename, if not given then filename would be DB name # Returns: # None ############################################################################### @@ -1079,8 +1086,10 @@ main() { save_cmd "docker ps -a" "docker.ps" save_cmd "docker top pmon" "docker.pmon" - for plugin_script in $PLUGIN_SCRIPTS; do - save_cmd "bash $plugin_script" "$(basename $plugin_script)" true + local -r dump_plugins="$(find ${PLUGINS_DIR} -type f -executable)" + for plugin in $dump_plugins; do + # save stdout output of plugin and gzip it + save_cmd "$plugin" "$(basename $plugin)" true false done save_saidump