Merge "Lock around ubuntu tarball download"
This commit is contained in:
commit
b44b798101
@ -14,14 +14,17 @@ DIB_RELEASE=${DIB_RELEASE:-trusty}
|
|||||||
BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-$DIB_RELEASE-server-cloudimg-$ARCH-root.tar.gz}
|
BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-$DIB_RELEASE-server-cloudimg-$ARCH-root.tar.gz}
|
||||||
SHA256SUMS=${SHA256SUMS:-https://${DIB_CLOUD_IMAGES##http?(s)://}/$DIB_RELEASE/current/SHA256SUMS}
|
SHA256SUMS=${SHA256SUMS:-https://${DIB_CLOUD_IMAGES##http?(s)://}/$DIB_RELEASE/current/SHA256SUMS}
|
||||||
CACHED_FILE=$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE
|
CACHED_FILE=$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE
|
||||||
|
CACHED_FILE_LOCK=$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE.lock
|
||||||
CACHED_SUMS=$DIB_IMAGE_CACHE/SHA256SUMS.ubuntu.$DIB_RELEASE.$ARCH
|
CACHED_SUMS=$DIB_IMAGE_CACHE/SHA256SUMS.ubuntu.$DIB_RELEASE.$ARCH
|
||||||
|
|
||||||
|
function get_ubuntu_tarball() {
|
||||||
if [ -n "$DIB_OFFLINE" -a -f "$CACHED_FILE" ] ; then
|
if [ -n "$DIB_OFFLINE" -a -f "$CACHED_FILE" ] ; then
|
||||||
echo "Not checking freshness of cached $CACHED_FILE."
|
echo "Not checking freshness of cached $CACHED_FILE."
|
||||||
else
|
else
|
||||||
echo "Fetching Base Image"
|
echo "Fetching Base Image"
|
||||||
$TMP_HOOKS_PATH/bin/cache-url $SHA256SUMS $CACHED_SUMS
|
$TMP_HOOKS_PATH/bin/cache-url $SHA256SUMS $CACHED_SUMS
|
||||||
$TMP_HOOKS_PATH/bin/cache-url $DIB_CLOUD_IMAGES/$DIB_RELEASE/current/$BASE_IMAGE_FILE $CACHED_FILE
|
$TMP_HOOKS_PATH/bin/cache-url \
|
||||||
|
$DIB_CLOUD_IMAGES/$DIB_RELEASE/current/$BASE_IMAGE_FILE $CACHED_FILE
|
||||||
pushd $DIB_IMAGE_CACHE
|
pushd $DIB_IMAGE_CACHE
|
||||||
if ! grep "$BASE_IMAGE_FILE" $CACHED_SUMS | sha256sum --check - ; then
|
if ! grep "$BASE_IMAGE_FILE" $CACHED_SUMS | sha256sum --check - ; then
|
||||||
# It is likely that an upstream http(s) proxy has given us a skewed
|
# It is likely that an upstream http(s) proxy has given us a skewed
|
||||||
@ -32,7 +35,8 @@ else
|
|||||||
# the image.
|
# the image.
|
||||||
$TMP_HOOKS_PATH/bin/cache-url -f $SHA256SUMS $CACHED_SUMS
|
$TMP_HOOKS_PATH/bin/cache-url -f $SHA256SUMS $CACHED_SUMS
|
||||||
if ! grep "$BASE_IMAGE_FILE" $CACHED_SUMS | sha256sum --check - ; then
|
if ! grep "$BASE_IMAGE_FILE" $CACHED_SUMS | sha256sum --check - ; then
|
||||||
$TMP_HOOKS_PATH/bin/cache-url -f $DIB_CLOUD_IMAGES/$DIB_RELEASE/current/$BASE_IMAGE_FILE $CACHED_FILE
|
$TMP_HOOKS_PATH/bin/cache-url -f \
|
||||||
|
$DIB_CLOUD_IMAGES/$DIB_RELEASE/current/$BASE_IMAGE_FILE $CACHED_FILE
|
||||||
grep "$BASE_IMAGE_FILE" $CACHED_SUMS | sha256sum --check -
|
grep "$BASE_IMAGE_FILE" $CACHED_SUMS | sha256sum --check -
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -44,3 +48,14 @@ sudo tar -C $TARGET_ROOT --numeric-owner -xzf $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE
|
|||||||
if [ -e "$TARGET_ROOT/lost+found" ]; then
|
if [ -e "$TARGET_ROOT/lost+found" ]; then
|
||||||
sudo rmdir $TARGET_ROOT/lost+found
|
sudo rmdir $TARGET_ROOT/lost+found
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
(
|
||||||
|
echo "Getting $CACHED_FILE_LOCK: $(date)"
|
||||||
|
# Wait up to 20 minutes for another process to download
|
||||||
|
if ! flock -w 1200 9 ; then
|
||||||
|
echo "Did not get $CACHED_FILE_LOCK: $(date)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
get_ubuntu_tarball
|
||||||
|
) 9> $CACHED_FILE_LOCK
|
||||||
|
Loading…
Reference in New Issue
Block a user