From 454f40d1216557e1180467c060829a7558682911 Mon Sep 17 00:00:00 2001 From: Henry Li <69694695+henryli001@users.noreply.github.com> Date: Wed, 29 Jun 2022 14:39:28 -0700 Subject: [PATCH] Add retry logic in runliveinstaller to ensure network access during pxe boot (#3257) * update runliveinstaller * Update toolkit/resources/imageconfigs/additionalfiles/iso_initrd/root/runliveinstaller Co-authored-by: Pawel Winogrodzki * Update toolkit/resources/imageconfigs/additionalfiles/iso_initrd/root/runliveinstaller Co-authored-by: Pawel Winogrodzki * change to lowercase * fix typos Co-authored-by: Henry Li Co-authored-by: Pawel Winogrodzki --- .../iso_initrd/root/runliveinstaller | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/toolkit/resources/imageconfigs/additionalfiles/iso_initrd/root/runliveinstaller b/toolkit/resources/imageconfigs/additionalfiles/iso_initrd/root/runliveinstaller index 332b52e875..8d81500b4d 100755 --- a/toolkit/resources/imageconfigs/additionalfiles/iso_initrd/root/runliveinstaller +++ b/toolkit/resources/imageconfigs/additionalfiles/iso_initrd/root/runliveinstaller @@ -10,7 +10,6 @@ CONFIG_ROOT=$ISO_ROOT/config UNATTENDED_CONFIG_FILE=$CONFIG_ROOT/unattended_config.json # PXE boot setup -SERVER_CONFIG_PATH="" CMDLINE=/proc/cmdline # parse script parameters: @@ -38,6 +37,19 @@ done mkdir -p $ISO_ROOT LABEL=CDROM +function retry { + local retry=0 + local limit=10 + local sleep_seconds=15 + while [ $retry -lt $limit ] + do + "$@" && break + echo "$@" failed. Retrying... + ((retry++)) + sleep $sleep_seconds + done +} + if grep -qs $ISO_ROOT /proc/mounts; then echo ISO root already mounted # Read from /proc/cmdline to get image configs from PXE server @@ -46,6 +58,12 @@ elif grep -q "image-config" $CMDLINE; then # $IMAGE_CONFIG_VALUE will be in this fixed format: http://PXE_SERVER_IP/RANDOM_PATH # CUT_DIRS will be an array of strings separated by '/' IFS='/' read -ra CUT_DIRS <<< $IMAGE_CONFIG_VALUE + + # It is possible that the installation environment does not have network access yet when + # this script is first run. So use a retry loop + PXE_SERVER_IP=$(echo "$IMAGE_CONFIG_VALUE" | sed -e 's|^[^/]*//||' -e 's|/.*$||') + retry ping -c 1 $PXE_SERVER_IP + # To disable generation of any extra directories and just download the contents within the directory, # use -nH to disable genration of host-prefix, "PXE_SERVER_IP". # To disable generation of "RANDOM_PATH", set --cut-dirs to the number of strings separated by '/'. @@ -58,16 +76,7 @@ else echo Attempt to mount the ISO root # It is possible that the partition isn't ready to be mounted when this script # is first run. So use a retry loop. - RETRY=0 - LIMIT=5 - SLEEPSECONDS=2 - while [ $RETRY -lt $LIMIT ] - do - mount -L $LABEL -o ro $ISO_ROOT && break - echo Mount failed. Retrying... - ((RETRY++)) - sleep $SLEEPSECONDS - done + retry mount -L $LABEL -o ro $ISO_ROOT fi if [[ ! -f "$UNATTENDED_CONFIG_FILE" ]]; then