From fbf8a4ab2b8e8a631d76abf6274f2bdb1bc9a138 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Sun, 6 Jul 2008 17:30:01 +0000 Subject: [PATCH] Rework the caching mechanism Following the introduction of ./configure options and the configuration files, this patch simplifies the caching settings: - the generation of the cache is done in the settings file, via GENERATE_CACHE (if set to "yes" it will enable the creation) - the cleaning of the cache is done also in the settings file, via the CLEAN_CACHE variable; set to empty it will disable the cache, otherwise it's interpreted as the number of days to keep the cache The location of the cache has also been moved from the current dir to under localstatedir, which is more FHS compliant (patch taken from the debian package); this means with localstatedir=/var, the location of the cache will be /var/cache/ganeti-instance-debootstrap. Reviewed-by: imsnah --- Makefile.am | 4 +++- NEWS | 20 ++++++++++++++++++++ create.in | 17 +++++++++++++---- defaults | 10 ++++++++++ 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Makefile.am b/Makefile.am index c6d2c76..1b6050f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,9 @@ dist_doc_DATA = COPYING NEWS README EXTRA_DIST = create.in defaults -do_subst = sed -e 's,[@]sysconfdir[@],$(sysconfdir),g' +do_subst = sed \ + -e 's,[@]sysconfdir[@],$(sysconfdir),g' \ + -e 's,[@]localstatedir[@],$(localstatedir),g' create: create.in Makefile $(do_subst) < $< > $@ diff --git a/NEWS b/NEWS index 52b44e4..aa8c135 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,23 @@ +Version 0.5 (unreleased) +------------------------ + +Most of the settings of the script have been moved to a configuration +file. Depending on the ./configure options, the location of this file +might be /etc/default/ganeti-instance-debootstrap or +/usr/local/etc/default/ganeti-instance-debootstrap. + +The cache generation and cleaning variables can be modified as follows: + +- to enable generating the cache, modify the config file and set + GENERATE_CACHE to "yes" +- to disable cleaning the cache, set CLEAN_CACHE to ""; or + alternatively, you can customize with this variable the number of days + after which to clear the cache + +Note that the cache file is no longer stored in the same directory as +the OS definition files, but (again depending on ./configure options) +usually under /var/cache/ganeti-instance-debootstrap. + Version 0.4 ----------- diff --git a/create.in b/create.in index ef32831..a1e82ff 100755 --- a/create.in +++ b/create.in @@ -33,9 +33,17 @@ fi : ${SUITE:="lenny"} : ${ARCH:=""} : ${EXTRA_PKGS:=""} +: ${GENERATE_CACHE:="yes"} +: ${CLEAN_CACHE:="14"} # number of days to keep a cache file + +CACHE_DIR="@localstatedir@/cache/ganeti-instance-debootstrap" + +if [ "$GENERATE_CACHE" = "yes" -a ! -d "$CACHE_DIR" ]; then + mkdir -p "$CACHE_DIR" +fi DPKG_ARCH=${ARCH:-`dpkg --print-architecture`} -CACHE_FILE="cache-${SUITE}-${DPKG_ARCH}.tar" +CACHE_FILE="$CACHE_DIR/cache-${SUITE}-${DPKG_ARCH}.tar" TEMP=`getopt -o i:b:s: -n '$0' -- "$@"` @@ -77,8 +85,9 @@ mount $MOUNT_OPTIONS $blockdev $TMPDIR # remove the cache file if it's old (> 2 weeks) and writable by the owner (the # default due to the standard umask) -if [ -f "$CACHE_FILE" ]; then - find "$CACHE_FILE" -perm -0200 -daystart -mtime +14 -print0 | \ +if [ "$CLEAN_CACHE" -a -d "$CACHE_DIR" ]; then + find "$CACHE_DIR" -name 'cache-*.tar' -type f \ + -daystart -mtime "+${CLEAN_CACHE}" -print0 | \ xargs -r0 rm -f fi @@ -101,7 +110,7 @@ else # interfaces as eth0, eth1, ... rm -f "$TMPDIR/etc/udev/rules.d/z25_persistent-net.rules" - if [ ! -e no_cache ]; then + if [ "$GENERATE_CACHE" = "yes" ]; then TMP_CACHE=`mktemp "${CACHE_FILE}.XXXXXX"` tar cf "$TMP_CACHE" -C $TMPDIR . mv -f "$TMP_CACHE" "$CACHE_FILE" diff --git a/defaults b/defaults index b320c08..ff143fe 100644 --- a/defaults +++ b/defaults @@ -28,3 +28,13 @@ # for etch amd64 (lenny doesn't have xen support in amd64): # EXTRA_PKGS="linux-image-xen-amd64" + +# GENERATE_CACHE: if set to yes (the default), create new cache files; +# any other value will disable the generation of cache files (but they +# will still be used if they exist) +GENERATE_CACHE="yes" + +# CLEAN_CACHE: should be set to the number of days after which to +# clean the cache; the default is 14 (two weeks); to disable cache +# cleaning, set it to an empty value ("") +CLEAN_CACHE="14" -- 1.7.2.5