Skip to content

Commit 37b31c5

Browse files
authored
[reboot-cause] Porting PR to fix a broken symlink of previous-reboot-cause file removal issue (sonic-host-services #46) (#14106)
Why I did it Porting/cherry-pick PR sonic-net/sonic-host-services#46 "show reboot-cause history" shows empty history. When the previous-reboot-cause has a broken symlink, And rebooting the system will not be able to generate a new symlink of the new previous-reboot-cause. admin@sonic:~$ show reboot-cause history Name Cause Time User Comment ------ ------- ------ ------ --------- How I did it Somehow, when the symlink file /host/reboot-cause/previous-reboot-cause is broken (which its destination files doesn't exist in this case), the current condition check "if os.path,exists(PREVIOUS_REBOOT_CAUSE_FILE)" will return False in determine-reboot-cause script. Hence, the current previous-reboot-cause is not been removed and the recreation of the new previous-reboot-cause failed. In case of previous-reboot-cause is a broken synlink file, add condition os.path.islink(PREVIOUS_REBOOT_CAUSE) to check and allow the remove operation happens. How to verify it Manually make the /host/reboot-cause/previous-reboot-cause to be a broken symlink file by removing its destination file reboot the system. "show reboot-cause history" should show the correct info Signed-off-by: mlok <[email protected]>
1 parent 75ad7b0 commit 37b31c5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/sonic-host-services/scripts/determine-reboot-cause

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def main():
223223
os.makedirs(REBOOT_CAUSE_DIR)
224224

225225
# Remove stale PREVIOUS_REBOOT_CAUSE_FILE if it exists
226-
if os.path.exists(PREVIOUS_REBOOT_CAUSE_FILE):
226+
if os.path.exists(PREVIOUS_REBOOT_CAUSE_FILE) or os.path.islink(PREVIOUS_REBOOT_CAUSE_FILE):
227227
os.remove(PREVIOUS_REBOOT_CAUSE_FILE)
228228

229229
previous_reboot_cause, additional_reboot_info = determine_reboot_cause()

0 commit comments

Comments
 (0)