Skip to content

Commit

Permalink
35coreos-live/coreos-livepxe-rootfs: retry fetching rootfs forever
Browse files Browse the repository at this point in the history
We don't know how long it will take for networking to come up, so let's
match Ignition's semantic of retrying to fetch remote resources forever.

`curl` doesn't natively have support for this, so wrap it in a `while`
loop. This also works around the fact that el8's `curl` doesn't support
`--retry-all-errors`.

This was previously added in coreos#929.

(cherry picked from commit d2776ed)
  • Loading branch information
jlebon authored and miabbott committed May 17, 2021
1 parent c8c74ac commit 1bb24a9
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,24 @@ elif [[ -n "${rootfs_url}" ]]; then
# First, reach out to the server to verify connectivity before
# trying to download and pipe content through other programs.
# Doing this allows us to retry all errors (including transient
# "no route to host" errors during startup), without using the
# --retry-all-errors, which is problematic (see curl man page)
# when piping the output.
curl_common_args="--silent --show-error --insecure --location --retry 5"
if ! curl --head --retry-all-errors $curl_common_args "${rootfs_url}" >/dev/null; then
# "no route to host" errors during startup). Note we can't use
# curl's --retry-all-errors here because it's not in el8's curl yet.
# We retry forever, matching Ignition's semantics.
curl_common_args="--silent --show-error --insecure --location"
while ! curl --head $curl_common_args "${rootfs_url}" >/dev/null; do
echo "Couldn't establish connectivity with the server specified by coreos.live.rootfs_url=" >&2
echo "Check that the URL is correct and can be reached." >&2
exit 1
fi
echo "Retrying in 5s..." >&2
sleep 5
done

# We don't need to verify TLS certificates because we're checking the
# image hash.
# bsdtar can read cpio archives and we already depend on it for
# coreos-liveiso-persist-osmet.service, so use it instead of cpio.
if ! curl $curl_common_args "${rootfs_url}" | \
# We shouldn't need a --retry here since we've just successfully HEADed the
# file, but let's add one just to be safe (e.g. if the connection just went
# online and flickers or something).
if ! curl $curl_common_args --retry 5 "${rootfs_url}" | \
rdcore stream-hash /etc/coreos-live-want-rootfs | \
bsdtar -xf - -C / ; then
echo "Couldn't fetch, verify, and unpack image specified by coreos.live.rootfs_url=" >&2
Expand Down

0 comments on commit 1bb24a9

Please sign in to comment.