Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions scripts/reboot
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/bash

declare -r EXIT_SUCCESS=0
declare -r EXIT_ERROR=1
declare -r WATCHDOG_UTIL="/usr/local/bin/watchdogutil"
declare -r PRE_REBOOT_HOOK="pre_reboot_hook"

DEVPATH="/usr/share/sonic/device"
PLAT_REBOOT="platform_reboot"
PLATFORM_UPDATE_REBOOT_CAUSE="platform_update_reboot_cause"
Expand Down Expand Up @@ -34,6 +40,8 @@ PLATFORM_FWUTIL_AU_REBOOT_HANDLE="platform_fw_au_reboot_handle"
REBOOT_SCRIPT_NAME=$(basename $0)
REBOOT_TYPE="${REBOOT_SCRIPT_NAME}"
TAG_LATEST=no
REBOOT_FLAGS=""
FORCE_REBOOT="no"

function debug()
{
Expand Down Expand Up @@ -121,9 +129,8 @@ function show_help_and_exit()
echo " "
echo " Available options:"
echo " -h, -? : getting this help"
echo " -f : execute reboot force"

exit 0
exit ${EXIT_SUCCESS}
}

function setup_reboot_variables()
Expand Down Expand Up @@ -166,13 +173,13 @@ function check_conflict_boot_in_fw_update()
FW_AU_TASK_FILE=$(compgen -G ${FW_AU_TASK_FILE_REGEX}) || true
if [[ -n "${FW_AU_TASK_FILE}" ]] && [[ ! -f "${FW_AU_TASK_FILE_EXP}" ]]; then
VERBOSE=yes debug "Firmware auto update scheduled for a different reboot: ${FW_AU_TASK_FILE}"
exit 1
exit ${EXIT_ERROR}
fi
}

function parse_options()
{
while getopts "h?vf" opt; do
while getopts "h?v" opt; do
case ${opt} in
h|\? )
show_help_and_exit
Expand All @@ -183,6 +190,10 @@ function parse_options()
t )
TAG_LATEST=no
;;
f )
REBOOT_FLAGS+=" -f"
FORCE_REBOOT="yes"
;;
esac
done
}
Expand All @@ -192,7 +203,7 @@ parse_options $@
# Exit if not superuser
if [[ "$EUID" -ne 0 ]]; then
echo "This command must be run as root" >&2
exit 1
exit ${EXIT_ERROR}
fi

debug "User requested rebooting device ..."
Expand Down Expand Up @@ -242,6 +253,23 @@ if [ -x ${DEVPATH}/${PLATFORM}/${PLATFORM_UPDATE_REBOOT_CAUSE} ]; then
${DEVPATH}/${PLATFORM}/${PLATFORM_UPDATE_REBOOT_CAUSE}
fi

if [ -x ${DEVPATH}/${PLATFORM}/${PRE_REBOOT_HOOK} ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

@vadymhlushko-mlnx why do we need pre_reboot_hook?

Copy link
Contributor Author

@vadymhlushko-mlnx vadymhlushko-mlnx Mar 11, 2024

Choose a reason for hiding this comment

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

@prgeor this PR comes in bundle [graceful reboot] Rename the platform_reboot to the pre_reboot_hook, remove the sysfs power cycle #18324.

For MLNX we removed the sysfs power cycle from the platform_reboot script and because the platform_reboot is no longer doing any reboot, we decided to rename it from platform_reboot to pre_reboot_hook

debug "Executing the pre-reboot script"
${DEVPATH}/${PLATFORM}/${PRE_REBOOT_HOOK}
EXIT_CODE=$?
if [[ ${EXIT_CODE} != ${EXIT_SUCCESS} ]]; then
if [[ "${FORCE_REBOOT}" != "yes" ]]; then
echo "Reboot is interrupted: use -f (force) to override"
exit ${EXIT_ERROR}
fi
fi
fi

if [ -x ${WATCHDOG_UTIL} ]; then
debug "Enabling the Watchdog before reboot"
${WATCHDOG_UTIL} arm
fi

if [ -x ${DEVPATH}/${PLATFORM}/${PLAT_REBOOT} ]; then
VERBOSE=yes debug "Rebooting with platform ${PLATFORM} specific tool ..."
${DEVPATH}/${PLATFORM}/${PLAT_REBOOT} $@
Expand All @@ -260,4 +288,4 @@ if [ -x ${DEVPATH}/${PLATFORM}/${PLAT_REBOOT} ]; then
fi

VERBOSE=yes debug "Issuing OS-level reboot ..." >&2
exec /sbin/reboot $@
exec /sbin/reboot ${REBOOT_FLAGS}