Skip to content

Commit

Permalink
[reboot cause] Move reboot-cause files to /host directory so they per…
Browse files Browse the repository at this point in the history
…sist across SONiC upgrades (#2490)

* [reboot cause] Move reboot-cause files to /host directory so they persist across SONiC upgrades

* [sonic-utilities] Update submodule to include related changes
  • Loading branch information
jleveque authored and lguohan committed Jan 29, 2019
1 parent 8f43cad commit 39b60d2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions files/image_config/platform/rc.local
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,31 @@ value_extract() {
done
}

# Set up previous and next reboot cause files
# Set up previous and next reboot cause files accordingly
process_reboot_cause() {
REBOOT_CAUSE_FILE="/var/cache/sonic/reboot-cause.txt"
PREVIOUS_REBOOT_CAUSE_FILE="/var/cache/sonic/previous-reboot-cause.txt"

# Set the previous reboot cause accordingly
# If this is the first boot after an image install, state that as the
# cause. Otherwise, move REBOOT_CAUSE_FILE to PREVIOUS_REBOOT_CAUSE_FILE.
# REBOOT_CAUSE_FILE should always exist, but we add the else case
# to ensure we always generate PREVIOUS_REBOOT_CAUSE_FILE here
REBOOT_CAUSE_DIR="/host/reboot-cause"
REBOOT_CAUSE_FILE="${REBOOT_CAUSE_DIR}/reboot-cause.txt"
PREVIOUS_REBOOT_CAUSE_FILE="${REBOOT_CAUSE_DIR}/previous-reboot-cause.txt"

mkdir -p $REBOOT_CAUSE_DIR

# If this is the first boot after an image install, store that as the
# previous reboot cause.
if [ -f $FIRST_BOOT_FILE ]; then
echo "SONiC image installation" > $PREVIOUS_REBOOT_CAUSE_FILE
elif [ -f $REBOOT_CAUSE_FILE ]; then
fi

# If there is an existing REBOOT_CAUSE_FILE, copy that file to
# PREVIOUS_REBOOT_CAUSE_FILE.
if [ -f $REBOOT_CAUSE_FILE ]; then
mv -f $REBOOT_CAUSE_FILE $PREVIOUS_REBOOT_CAUSE_FILE
else
echo "Unknown reboot cause" > $PREVIOUS_REBOOT_CAUSE_FILE
fi

# Log the previous reboot cause to the syslog
logger "Previous reboot cause: $(cat $PREVIOUS_REBOOT_CAUSE_FILE)"

# Set the default cause for the next reboot
echo "Unexpected reboot" > $REBOOT_CAUSE_FILE
}
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-utilities

0 comments on commit 39b60d2

Please sign in to comment.