Skip to content

Commit

Permalink
Add support to make determine/process reboot-cause services restartable
Browse files Browse the repository at this point in the history
Signed-off-by: anamehra <[email protected]>
  • Loading branch information
anamehra committed Nov 18, 2023
1 parent 586b1e9 commit ea8cbfd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scripts/determine-reboot-cause
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ REBOOT_CAUSE_FILE = os.path.join(REBOOT_CAUSE_DIR, "reboot-cause.txt")
PREVIOUS_REBOOT_CAUSE_FILE = os.path.join(REBOOT_CAUSE_DIR, "previous-reboot-cause.json")
FIRST_BOOT_PLATFORM_FILE = "/tmp/notify_firstboot_to_platform"
REBOOT_TYPE_KEXEC_FILE = "/proc/cmdline"
REBOOT_PROCESSED_FILE = "/tmp/previous-reboot-cause-processed"
# The following SONIC_BOOT_TYPEs come from the warm/fast reboot script which is in sonic-utilities
# Because the system can be rebooted from some old versions, we have to take all possible BOOT options into consideration.
# On 201803, 201807 we have
Expand Down Expand Up @@ -218,6 +219,10 @@ def main():
sonic_logger.log_error("User {} does not have permission to execute".format(pwd.getpwuid(os.getuid()).pw_name))
sys.exit("This utility must be run as root")

if os.path.exists(REBOOT_PROCESSED_FILE):
sonic_logger.log_info("User {} : reboot-cause already processed. Nothing to do. Exiting...".format(pwd.getpwuid(os.getuid()).pw_name))
sys.exit(0)

# Create REBOOT_CAUSE_DIR if it doesn't exist
if not os.path.exists(REBOOT_CAUSE_DIR):
os.makedirs(REBOOT_CAUSE_DIR)
Expand Down Expand Up @@ -257,6 +262,10 @@ def main():
with open(REBOOT_CAUSE_FILE, "w") as cause_file:
cause_file.write(REBOOT_CAUSE_UNKNOWN)

# Create tmp reboot processed file to mark processing of last reboot cause during current boot.
# This is used to prevent reprocessing of reboot cause if this service restarts.
with open(REBOOT_PROCESSED_FILE, "w") as reboot_processed_file:
reboot_processed_file.write("processed last reboot cause")

if __name__ == "__main__":
main()

0 comments on commit ea8cbfd

Please sign in to comment.