diff --git a/files/image_config/platform/rc.local b/files/image_config/platform/rc.local index acac42e326e1..3596eb18419c 100755 --- a/files/image_config/platform/rc.local +++ b/files/image_config/platform/rc.local @@ -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 } diff --git a/src/sonic-utilities b/src/sonic-utilities index 3ce8952ca43c..97ac8c7cbd32 160000 --- a/src/sonic-utilities +++ b/src/sonic-utilities @@ -1 +1 @@ -Subproject commit 3ce8952ca43c2d5015ae90b13aa8a4644bab4c19 +Subproject commit 97ac8c7cbd3284c3a1c3443bb2156309f8fc65ea