Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial support for keeping track of and displaying reboot cause #1812

Merged
merged 4 commits into from
Jun 28, 2018
Merged

Add initial support for keeping track of and displaying reboot cause #1812

merged 4 commits into from
Jun 28, 2018

Conversation

jleveque
Copy link
Contributor

@jleveque jleveque commented Jun 25, 2018

- What I did

Add initial support for keeping track of and displaying reboot cause

- How I did it

  • Upon boot, rc.local determines the cause of the previous reboot and generates /var/cache/sonic/previous-reboot-cause.txt to contain the cause. This is determined as follows:

    • If this is the first boot after an image upgrade, it writes SONiC image installation
    • Otherwise it moves /var/cache/sonic/reboot-cause.txt (which should contain the cause of the previous reboot -- see below) to /var/cache/sonic/previous-reboot-cause.txt
    • In the unlikely event /var/cache/sonic/reboot-cause.txt does not exist, it writes Unknown reboot cause
  • rc.local then generates a new /var/cache/sonic/reboot-cause.txt file containing the default cause of Unexpected reboot. This file should be updated before going down for reboot if the cause is known. This is currently only done in the reboot wrapper script in sonic-utilities, which updates the file when a user issues the reboot command.

  • The new command show reboot-cause can be used to display the previous reboot cause. Sample output:

admin@sonic:~$ show reboot-cause 
User issued reboot command [User: admin, Time: Sat Jun 23 01:30:43 UTC 2018]
admin@sonic:~$ show reboot-cause 
Unexpected reboot
  • Also reorganized rc.local such that the file contains (in order) constant declarations, function definitions, main body

  • Also renamed constants using all caps

- How to verify it

  • Try rebooting the device by both command and by hard power cycle. Once booted, run show reboot-cause and confirm the output is expected.

- For the future

  • We can abstract a platform-agnostic way to determine whether the device rebooted due to a hard power-cycle, and possibly other reboot causes.

@@ -11,6 +11,9 @@
#
# By default this script does nothing.

eval SONIC_VERSION=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ")
Copy link
Collaborator

@qiluo-msft qiluo-msft Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SONIC_VERSION [](start = 5, length = 13)

The cat/grep way will include quotation mark.
Try

sonic-cfggen -y /etc/sonic/sonic_version.yml -v build_version
``` #Closed

Copy link
Contributor Author

@jleveque jleveque Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't write this, I just moved it. The use of eval evaluates the expression inside the quotation marks. I can change and test it, though, if you'd like.

# REBOOT_CAUSE_FILE should always exist, but we add the else case
# to ensure we always generate PREVIOUS_REBOOT_CAUSE_FILE here
if [ -f $FIRST_BOOT_FILE ]; then
echo "SONiC firmware upgrade" > $PREVIOUS_REBOOT_CAUSE_FILE
Copy link
Collaborator

@qiluo-msft qiluo-msft Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SONiC firmware upgrade [](start = 14, length = 22)

How about "First boot". "Firmware" is confusing. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "first boot" is far more confusing to an end-user, especially if the device has been in production for a while and was recently upgraded. If you don't like "firmware," I would suggest SONiC operating system upgrade, SONiC OS upgrade or SONiC image upgrade as alternatives.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Then 'upgrade' is also confusing. Technically the first SONiC installation is not a upgrade.

Maybe the general "Unknown reboot cause" is good enough, since the currently implementation know nothing about first reboot and sonic upgrade.


In reply to: 197971849 [](ancestors = 197971849)

Copy link
Contributor Author

@jleveque jleveque Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, but I think it's more useful to know that the last time the device rebooted was due to a firmware upgrade, as opposed to stating "Unknown reboot cause". Maybe SONiC image installation?

Copy link
Collaborator

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As comments.

@lguohan lguohan merged commit 301fc28 into sonic-net:master Jun 28, 2018
@jleveque jleveque deleted the reboot_cause branch June 28, 2018 17:59
volodymyrsamotiy added a commit to volodymyrsamotiy/sonic-buildimage that referenced this pull request Sep 13, 2021
* d03ba4f [202012] [portstat, intfstat] added rates and utilization  (sonic-net#1812)
* 499ad3f [config reload] Fix config reload failure due to sonic.target job cancellation (sonic-net#1814)
* 96d658c [202012][sonic installer] Add swap setup support (sonic-net#1815)
* a9c6970 platform pre-check for reboot in 202012 branch (sonic-net#1788)
* 0e0478b Unify the number format in the ourput of portstat and pfcstat in all cases (sonic-net#1795)
* 2d1e00e [ecnconfig] Fix exception seen during display and add unit tests (sonic-net#1784) (sonic-net#1789)

Signed-off-by: Volodymyr Samotiy <volodymyrs@nvidia.com>
vivekrnv added a commit to vivekrnv/sonic-buildimage that referenced this pull request Sep 13, 2021
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>

d03ba4fa [202012] [portstat, intfstat] added rates and utilization  (sonic-net#1812)
499ad3f4 [config reload] Fix config reload failure due to sonic.target job cancellation (sonic-net#1814)
96d658c2 [202012][sonic installer] Add swap setup support (sonic-net#1815)
a9c69702 platform pre-check for reboot in 202012 branch (sonic-net#1788)
0e0478ba Unify the number format in the ourput of portstat and pfcstat in all cases (sonic-net#1795)
2d1e00ed [ecnconfig] Fix exception seen during display and add unit tests (sonic-net#1784) (sonic-net#1789)
lguohan pushed a commit that referenced this pull request Sep 14, 2021
* d03ba4f [202012] [portstat, intfstat] added rates and utilization  (#1812)
* 499ad3f [config reload] Fix config reload failure due to sonic.target job cancellation (#1814)
* 96d658c [202012][sonic installer] Add swap setup support (#1815)
* a9c6970 platform pre-check for reboot in 202012 branch (#1788)
* 0e0478b Unify the number format in the ourput of portstat and pfcstat in all cases (#1795)
* 2d1e00e [ecnconfig] Fix exception seen during display and add unit tests (#1784) (#1789)

Signed-off-by: Volodymyr Samotiy <volodymyrs@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants