Skip to content

Commit 71a1e25

Browse files
authored
[fast/warm reboot] add some sanity check before warm reboot (sonic-net#510)
* [fast/warm reboot] carve out variable setup code to a function Signed-off-by: Ying Xie <[email protected]> * [fast/warm reboot] reorder code so that we have a clear main start point - Parse option before checking privilege so all users could get help information. Signed-off-by: Ying Xie <[email protected]> * [fast/warm reboot] add some reboot pre-checks - Make sure that /host has enough space and write-able. - Make sure the next image is available. Signed-off-by: Ying Xie <[email protected]> * fix error message
1 parent 148d455 commit 71a1e25

File tree

1 file changed

+61
-24
lines changed

1 file changed

+61
-24
lines changed

scripts/fast-reboot

+61-24
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@ REBOOT_METHOD="/sbin/kexec -e"
1313
ASSISTANT_IP_LIST=""
1414
ASSISTANT_SCRIPT="/usr/bin/neighbor_advertiser"
1515

16+
# Require 100M available on the hard drive for warm reboot temp files,
17+
# Size is in 1K blocks:
18+
MIN_HD_SPACE_NEEDED=100000
19+
1620
EXIT_SUCCESS=0
1721
EXIT_FAILURE=1
1822
EXIT_NOT_SUPPORTED=2
23+
EXIT_FILE_SYSTEM_FULL=3
24+
EXIT_NEXT_IMAGE_NOT_EXISTS=4
1925
EXIT_ORCHAGENT_SHUTDOWN=10
2026
EXIT_SYNCD_SHUTDOWN=11
2127

22-
# Check root privileges
23-
if [[ "$EUID" -ne 0 ]]
24-
then
25-
echo "This command must be run as root" >&2
26-
exit "${EXIT_FAILURE}"
27-
fi
28-
2928
function error()
3029
{
3130
echo $@ >&2
@@ -82,8 +81,6 @@ function parseOptions()
8281
done
8382
}
8483

85-
sonic_asic_type=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
86-
8784
function clear_fast_boot()
8885
{
8986
debug "${REBOOT_TYPE} failure ($?) cleanup ..."
@@ -212,8 +209,60 @@ function teardown_control_plane_assistant()
212209
fi
213210
}
214211
212+
function setup_reboot_variables()
213+
{
214+
# Kernel and initrd image
215+
NEXT_SONIC_IMAGE=$(sonic_installer list | grep "Next: " | cut -d ' ' -f 2)
216+
IMAGE_PATH="/host/image-${NEXT_SONIC_IMAGE#SONiC-OS-}"
217+
if grep -q aboot_platform= /host/machine.conf; then
218+
KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)"
219+
BOOT_OPTIONS="$(cat "$IMAGE_PATH/kernel-cmdline" | tr '\n' ' ') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
220+
elif grep -q onie_platform= /host/machine.conf; then
221+
KERNEL_OPTIONS=$(cat /host/grub/grub.cfg | sed "/$NEXT_SONIC_IMAGE'/,/}/"'!'"g" | grep linux)
222+
KERNEL_IMAGE="/host$(echo $KERNEL_OPTIONS | cut -d ' ' -f 2)"
223+
BOOT_OPTIONS="$(echo $KERNEL_OPTIONS | sed -e 's/\s*linux\s*/BOOT_IMAGE=/') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
224+
else
225+
error "Unknown bootloader. ${REBOOT_TYPE} is not supported."
226+
exit "${EXIT_NOT_SUPPORTED}"
227+
fi
228+
INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g')
229+
}
230+
231+
function reboot_pre_check()
232+
{
233+
# Make sure that the file system is normal: read-write able
234+
filename="/host/test-`date +%Y%m%d-%H%M%S`"
235+
if [[ ! -f ${filename} ]]; then
236+
touch ${filename}
237+
fi
238+
rm ${filename}
239+
240+
# Make sure /host has enough space for warm reboot temp files
241+
avail=$(df -k /host | tail -1 | awk '{ print $4 }')
242+
if [[ ${avail} -lt ${MIN_HD_SPACE_NEEDED} ]]; then
243+
debug "/host has ${avail}K bytes available, not enough for warm reboot."
244+
exit ${EXIT_FILE_SYSTEM_FULL}
245+
fi
246+
247+
# Make sure that the next image exists
248+
if [[ ! -d ${IMAGE_PATH} ]]; then
249+
debug "Next image ${NEXT_SONIC_IMAGE} doesn't exist ..."
250+
exit ${EXIT_NEXT_IMAGE_NOT_EXISTS}
251+
fi
252+
}
253+
254+
# main starts here
215255
parseOptions $@
216256
257+
# Check root privileges
258+
if [[ "$EUID" -ne 0 ]]
259+
then
260+
echo "This command must be run as root" >&2
261+
exit "${EXIT_FAILURE}"
262+
fi
263+
264+
sonic_asic_type=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
265+
217266
# Check reboot type supported
218267
BOOT_TYPE_ARG="cold"
219268
case "$REBOOT_TYPE" in
@@ -249,21 +298,9 @@ then
249298
/sbin/kexec -u
250299
fi
251300
252-
# Kernel and initrd image
253-
NEXT_SONIC_IMAGE=$(sonic_installer list | grep "Next: " | cut -d ' ' -f 2)
254-
if grep -q aboot_platform= /host/machine.conf; then
255-
IMAGE_PATH="/host/image-${NEXT_SONIC_IMAGE#SONiC-OS-}"
256-
KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)"
257-
BOOT_OPTIONS="$(cat "$IMAGE_PATH/kernel-cmdline" | tr '\n' ' ') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
258-
elif grep -q onie_platform= /host/machine.conf; then
259-
KERNEL_OPTIONS=$(cat /host/grub/grub.cfg | sed "/$NEXT_SONIC_IMAGE'/,/}/"'!'"g" | grep linux)
260-
KERNEL_IMAGE="/host$(echo $KERNEL_OPTIONS | cut -d ' ' -f 2)"
261-
BOOT_OPTIONS="$(echo $KERNEL_OPTIONS | sed -e 's/\s*linux\s*/BOOT_IMAGE=/') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
262-
else
263-
error "Unknown bootloader. ${REBOOT_TYPE} is not supported."
264-
exit "${EXIT_NOT_SUPPORTED}"
265-
fi
266-
INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g')
301+
setup_reboot_variables
302+
303+
reboot_pre_check
267304
268305
# Install new FW for mellanox platforms before control plane goes down
269306
# So on boot switch will not spend time to upgrade FW increasing the CP downtime

0 commit comments

Comments
 (0)