Skip to content

Commit

Permalink
[fast/warm reboot] add some sanity check before warm reboot (sonic-ne…
Browse files Browse the repository at this point in the history
…t#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
  • Loading branch information
yxieca authored Apr 16, 2019
1 parent 148d455 commit 71a1e25
Showing 1 changed file with 61 additions and 24 deletions.
85 changes: 61 additions & 24 deletions scripts/fast-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ REBOOT_METHOD="/sbin/kexec -e"
ASSISTANT_IP_LIST=""
ASSISTANT_SCRIPT="/usr/bin/neighbor_advertiser"

# Require 100M available on the hard drive for warm reboot temp files,
# Size is in 1K blocks:
MIN_HD_SPACE_NEEDED=100000

EXIT_SUCCESS=0
EXIT_FAILURE=1
EXIT_NOT_SUPPORTED=2
EXIT_FILE_SYSTEM_FULL=3
EXIT_NEXT_IMAGE_NOT_EXISTS=4
EXIT_ORCHAGENT_SHUTDOWN=10
EXIT_SYNCD_SHUTDOWN=11

# Check root privileges
if [[ "$EUID" -ne 0 ]]
then
echo "This command must be run as root" >&2
exit "${EXIT_FAILURE}"
fi

function error()
{
echo $@ >&2
Expand Down Expand Up @@ -82,8 +81,6 @@ function parseOptions()
done
}

sonic_asic_type=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)

function clear_fast_boot()
{
debug "${REBOOT_TYPE} failure ($?) cleanup ..."
Expand Down Expand Up @@ -212,8 +209,60 @@ function teardown_control_plane_assistant()
fi
}
function setup_reboot_variables()
{
# Kernel and initrd image
NEXT_SONIC_IMAGE=$(sonic_installer list | grep "Next: " | cut -d ' ' -f 2)
IMAGE_PATH="/host/image-${NEXT_SONIC_IMAGE#SONiC-OS-}"
if grep -q aboot_platform= /host/machine.conf; then
KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)"
BOOT_OPTIONS="$(cat "$IMAGE_PATH/kernel-cmdline" | tr '\n' ' ') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
elif grep -q onie_platform= /host/machine.conf; then
KERNEL_OPTIONS=$(cat /host/grub/grub.cfg | sed "/$NEXT_SONIC_IMAGE'/,/}/"'!'"g" | grep linux)
KERNEL_IMAGE="/host$(echo $KERNEL_OPTIONS | cut -d ' ' -f 2)"
BOOT_OPTIONS="$(echo $KERNEL_OPTIONS | sed -e 's/\s*linux\s*/BOOT_IMAGE=/') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
else
error "Unknown bootloader. ${REBOOT_TYPE} is not supported."
exit "${EXIT_NOT_SUPPORTED}"
fi
INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g')
}
function reboot_pre_check()
{
# Make sure that the file system is normal: read-write able
filename="/host/test-`date +%Y%m%d-%H%M%S`"
if [[ ! -f ${filename} ]]; then
touch ${filename}
fi
rm ${filename}
# Make sure /host has enough space for warm reboot temp files
avail=$(df -k /host | tail -1 | awk '{ print $4 }')
if [[ ${avail} -lt ${MIN_HD_SPACE_NEEDED} ]]; then
debug "/host has ${avail}K bytes available, not enough for warm reboot."
exit ${EXIT_FILE_SYSTEM_FULL}
fi
# Make sure that the next image exists
if [[ ! -d ${IMAGE_PATH} ]]; then
debug "Next image ${NEXT_SONIC_IMAGE} doesn't exist ..."
exit ${EXIT_NEXT_IMAGE_NOT_EXISTS}
fi
}
# main starts here
parseOptions $@
# Check root privileges
if [[ "$EUID" -ne 0 ]]
then
echo "This command must be run as root" >&2
exit "${EXIT_FAILURE}"
fi
sonic_asic_type=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
# Check reboot type supported
BOOT_TYPE_ARG="cold"
case "$REBOOT_TYPE" in
Expand Down Expand Up @@ -249,21 +298,9 @@ then
/sbin/kexec -u
fi
# Kernel and initrd image
NEXT_SONIC_IMAGE=$(sonic_installer list | grep "Next: " | cut -d ' ' -f 2)
if grep -q aboot_platform= /host/machine.conf; then
IMAGE_PATH="/host/image-${NEXT_SONIC_IMAGE#SONiC-OS-}"
KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)"
BOOT_OPTIONS="$(cat "$IMAGE_PATH/kernel-cmdline" | tr '\n' ' ') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
elif grep -q onie_platform= /host/machine.conf; then
KERNEL_OPTIONS=$(cat /host/grub/grub.cfg | sed "/$NEXT_SONIC_IMAGE'/,/}/"'!'"g" | grep linux)
KERNEL_IMAGE="/host$(echo $KERNEL_OPTIONS | cut -d ' ' -f 2)"
BOOT_OPTIONS="$(echo $KERNEL_OPTIONS | sed -e 's/\s*linux\s*/BOOT_IMAGE=/') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
else
error "Unknown bootloader. ${REBOOT_TYPE} is not supported."
exit "${EXIT_NOT_SUPPORTED}"
fi
INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g')
setup_reboot_variables
reboot_pre_check
# Install new FW for mellanox platforms before control plane goes down
# So on boot switch will not spend time to upgrade FW increasing the CP downtime
Expand Down

0 comments on commit 71a1e25

Please sign in to comment.