From b25d0337b8b97b70145fbde54d4ac4a5e07ca2a1 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Sun, 22 Oct 2017 16:16:04 +0000 Subject: [PATCH] Move to a common lock-file directory In a couple of places we use flock for critical sections, but we leave lockfiles around in various locations which can be confusing. Introduce DIB_LOCKFILES global (under ~/.cache/dib/lockfiles) and write lockfiles in there. Fix up removal of the lockfile in the yum path; we just want to make sure we cleanup the .rpmmacros file, but we don't need to remove the lockfile as well. Co-Authored-By: Andreas Florath Change-Id: Ie810b2836be521325afe923708d046112e1e1e20 --- .../elements/ubuntu-core/root.d/10-cache-ubuntu-image | 2 +- .../elements/ubuntu/root.d/10-cache-ubuntu-tarball | 2 +- .../elements/yum-minimal/root.d/08-yum-chroot | 6 +++--- diskimage_builder/lib/disk-image-create | 7 +++++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/diskimage_builder/elements/ubuntu-core/root.d/10-cache-ubuntu-image b/diskimage_builder/elements/ubuntu-core/root.d/10-cache-ubuntu-image index cd00ca2a9..9f16abfd6 100755 --- a/diskimage_builder/elements/ubuntu-core/root.d/10-cache-ubuntu-image +++ b/diskimage_builder/elements/ubuntu-core/root.d/10-cache-ubuntu-image @@ -29,7 +29,7 @@ DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://cdimage.ubuntu.com/ubuntu-core/relea BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-ubuntu-core-$numeric_release-core-$ARCH.tar.gz} SHA256SUMS=${SHA256SUMS:-$DIB_CLOUD_IMAGES/SHA256SUMS} CACHED_FILE=$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE -CACHED_FILE_LOCK=$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE.lock +CACHED_FILE_LOCK=$DIB_LOCKFILES/$BASE_IMAGE_FILE.lock CACHED_SUMS=$DIB_IMAGE_CACHE/SHA256SUMS.ubuntu-core.$DIB_RELEASE.$ARCH function get_ubuntu_tarball() { diff --git a/diskimage_builder/elements/ubuntu/root.d/10-cache-ubuntu-tarball b/diskimage_builder/elements/ubuntu/root.d/10-cache-ubuntu-tarball index a6ece7680..41241a5b5 100755 --- a/diskimage_builder/elements/ubuntu/root.d/10-cache-ubuntu-tarball +++ b/diskimage_builder/elements/ubuntu/root.d/10-cache-ubuntu-tarball @@ -17,7 +17,7 @@ DIB_RELEASE=${DIB_RELEASE:-trusty} 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} CACHED_FILE=$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE -CACHED_FILE_LOCK=$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE.lock +CACHED_FILE_LOCK=$DIB_LOCKFILES/$BASE_IMAGE_FILE.lock CACHED_SUMS=$DIB_IMAGE_CACHE/SHA256SUMS.ubuntu.$DIB_RELEASE.$ARCH function get_ubuntu_tarball() { diff --git a/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot b/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot index 0e5291e56..c69aa7a4f 100755 --- a/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot +++ b/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot @@ -201,14 +201,14 @@ function _install_pkg_manager { --installroot $TARGET_ROOT \ install $@ ${_lang_pack} ${_extra_pkgs} && rc=$? || rc=$? - # We modified the base system - make sure we clean up always! - rm $HOME/.rpmmacros.dib.lock + # Note we've modified the base system's .rpmmacros. Ensure we + # clean it up *always* # sed makes it easy to remove last line, but not last n lines... sed -i '$ d' $HOME/.rpmmacros; sed -i '$ d' $HOME/.rpmmacros; if [ $rc != 0 ]; then die "Initial yum install to chroot failed! Can not continue." fi - ) 9>$HOME/.rpmmacros.dib.lock + ) 9>$DIB_LOCKFILES/.rpmmacros.dib.lock # Set gpg path back because subsequent actions will take place in # the chroot diff --git a/diskimage_builder/lib/disk-image-create b/diskimage_builder/lib/disk-image-create index 70b1db7aa..24eb62ddf 100644 --- a/diskimage_builder/lib/disk-image-create +++ b/diskimage_builder/lib/disk-image-create @@ -166,9 +166,16 @@ done export DIB_DEBUG_TRACE +# TODO: namespace this under ~/.cache/dib/ for consistency export DIB_IMAGE_CACHE=${DIB_IMAGE_CACHE:-~/.cache/image-create} mkdir -p $DIB_IMAGE_CACHE +# We have a couple of critical sections (touching parts of the host +# system or download images to common cache) that we use flock around. +# Use this directory for lockfiles. +export DIB_LOCKFILES=${DIB_LOCKFILES:-~/.cache/dib/lockfiles} +mkdir -p $DIB_LOCKFILES + if [ "$CLEAR_ENV" = "1" -a "$HOME" != "" ]; then echo "Re-execing to clear environment." echo "(note this will prevent much of the local_config element from working)"