Skip to content

Commit 8d4f6b7

Browse files
vadymhlushko-mlnxjianyuewu
authored andcommitted
[graceful reboot] Add the pre_reboot_hook script execution, add the watchdog arm before the reboot (sonic-net#3203)
Signed-off-by: vadymhlushko-mlnx <[email protected]>
1 parent 8e71e65 commit 8d4f6b7

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

scripts/reboot

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/bash
2+
3+
declare -r EXIT_SUCCESS=0
4+
declare -r EXIT_ERROR=1
5+
declare -r WATCHDOG_UTIL="/usr/local/bin/watchdogutil"
6+
declare -r PRE_REBOOT_HOOK="pre_reboot_hook"
7+
28
DEVPATH="/usr/share/sonic/device"
39
PLAT_REBOOT="platform_reboot"
410
PLATFORM_UPDATE_REBOOT_CAUSE="platform_update_reboot_cause"
@@ -34,6 +40,8 @@ PLATFORM_FWUTIL_AU_REBOOT_HANDLE="platform_fw_au_reboot_handle"
3440
REBOOT_SCRIPT_NAME=$(basename $0)
3541
REBOOT_TYPE="${REBOOT_SCRIPT_NAME}"
3642
TAG_LATEST=no
43+
REBOOT_FLAGS=""
44+
FORCE_REBOOT="no"
3745

3846
function debug()
3947
{
@@ -122,7 +130,7 @@ function show_help_and_exit()
122130
echo " Available options:"
123131
echo " -h, -? : getting this help"
124132

125-
exit 0
133+
exit ${EXIT_SUCCESS}
126134
}
127135

128136
function setup_reboot_variables()
@@ -165,7 +173,7 @@ function check_conflict_boot_in_fw_update()
165173
FW_AU_TASK_FILE=$(compgen -G ${FW_AU_TASK_FILE_REGEX}) || true
166174
if [[ -n "${FW_AU_TASK_FILE}" ]] && [[ ! -f "${FW_AU_TASK_FILE_EXP}" ]]; then
167175
VERBOSE=yes debug "Firmware auto update scheduled for a different reboot: ${FW_AU_TASK_FILE}"
168-
exit 1
176+
exit ${EXIT_ERROR}
169177
fi
170178
}
171179

@@ -182,6 +190,10 @@ function parse_options()
182190
t )
183191
TAG_LATEST=no
184192
;;
193+
f )
194+
REBOOT_FLAGS+=" -f"
195+
FORCE_REBOOT="yes"
196+
;;
185197
esac
186198
done
187199
}
@@ -191,7 +203,7 @@ parse_options $@
191203
# Exit if not superuser
192204
if [[ "$EUID" -ne 0 ]]; then
193205
echo "This command must be run as root" >&2
194-
exit 1
206+
exit ${EXIT_ERROR}
195207
fi
196208

197209
debug "User requested rebooting device ..."
@@ -241,6 +253,23 @@ if [ -x ${DEVPATH}/${PLATFORM}/${PLATFORM_UPDATE_REBOOT_CAUSE} ]; then
241253
${DEVPATH}/${PLATFORM}/${PLATFORM_UPDATE_REBOOT_CAUSE}
242254
fi
243255

256+
if [ -x ${DEVPATH}/${PLATFORM}/${PRE_REBOOT_HOOK} ]; then
257+
debug "Executing the pre-reboot script"
258+
${DEVPATH}/${PLATFORM}/${PRE_REBOOT_HOOK}
259+
EXIT_CODE=$?
260+
if [[ ${EXIT_CODE} != ${EXIT_SUCCESS} ]]; then
261+
if [[ "${FORCE_REBOOT}" != "yes" ]]; then
262+
echo "Reboot is interrupted: use -f (force) to override"
263+
exit ${EXIT_ERROR}
264+
fi
265+
fi
266+
fi
267+
268+
if [ -x ${WATCHDOG_UTIL} ]; then
269+
debug "Enabling the Watchdog before reboot"
270+
${WATCHDOG_UTIL} arm
271+
fi
272+
244273
if [ -x ${DEVPATH}/${PLATFORM}/${PLAT_REBOOT} ]; then
245274
VERBOSE=yes debug "Rebooting with platform ${PLATFORM} specific tool ..."
246275
${DEVPATH}/${PLATFORM}/${PLAT_REBOOT} $@
@@ -259,4 +288,4 @@ if [ -x ${DEVPATH}/${PLATFORM}/${PLAT_REBOOT} ]; then
259288
fi
260289

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

0 commit comments

Comments
 (0)