[[PATCH][debci]] bin/debci-setup: Do not set the timestamp if setup failed
If the system does not have a dependency installed or an error occurs the
setup script fails and creates a timestamp for the testbed.
This blocks subsequent attempts to setup/update the testbed since it finds the
existing timestamp.
Instead, the setup script should create a temporary timestamp for the testbed,
remove it when setup is successful, and then create the official timestamp.
---
backends/lxc/create-testbed | 2 ++
backends/schroot/create-testbed | 1 +
backends/schroot/update-testbed | 2 ++
bin/debci-setup | 14 +++++++++++---
lib/environment.sh | 1 +
lib/functions.sh | 6 ++++++
6 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/backends/lxc/create-testbed b/backends/lxc/create-testbed
index cc17ab5..7245a5e 100755
--- a/backends/lxc/create-testbed
+++ b/backends/lxc/create-testbed
@@ -117,3 +117,5 @@ chroot "$rootfs" \
--shell /bin/sh \
--home /home/debci \
debci
+
+remove_testbed_setup_progress_timestamp
diff --git a/backends/schroot/create-testbed b/backends/schroot/create-testbed
index fda596e..08c3702 100755
--- a/backends/schroot/create-testbed
+++ b/backends/schroot/create-testbed
@@ -147,3 +147,4 @@ if ! which schroot >/dev/null; then
fi
setup_suite
+remove_testbed_setup_progress_timestamp
diff --git a/backends/schroot/update-testbed b/backends/schroot/update-testbed
index 69c76f0..4adebe4 100755
--- a/backends/schroot/update-testbed
+++ b/backends/schroot/update-testbed
@@ -26,3 +26,5 @@ DEBIAN_FRONTEND=noninteractive schroot \
--directory / \
--user root \
-- apt-get dist-upgrade -q -y
+
+remove_testbed_setup_progress_timestamp
diff --git a/bin/debci-setup b/bin/debci-setup
index 46d30b4..ee342ac 100755
--- a/bin/debci-setup
+++ b/bin/debci-setup
@@ -19,11 +19,14 @@ if which create-testbed >/dev/null 2>/dev/null; then
log "Starting testbed setup: $(date)"
+ touch "$debci_testbed_setup_progress_timestamp"
+
if [ -e "$debci_testbed_timestamp" ]; then
last_update=$(stat --format=%Y "$debci_testbed_timestamp")
now=$(date +%s)
if [ $(($now - $last_update)) -le 43200 ]; then # 12h
log "I: testbed already updated in the last 12h, no need to update"
+ remove_testbed_setup_progress_timestamp
exit
fi
fi
@@ -49,10 +52,15 @@ if which create-testbed >/dev/null 2>/dev/null; then
run_with_exclusive_lock "$debci_testbed_lock" create-testbed >>$log 2>&1
fi
- # record timestamp
- touch "$debci_testbed_timestamp"
+ # record timestamp if setup finished correctly
+ if [ ! -e "$debci_testbed_setup_progress_timestamp" ]; then
+ touch "$debci_testbed_timestamp"
+ status="Finished testbed setup: $(date)"
+ else
+ status="E: Testbed setup did not finish properly."
+ fi
- log "Finished testbed setup: $(date)"
+ log $status
else
log "I: $debci_backend backend does not provide a way to create a testbed"
fi
diff --git a/lib/environment.sh b/lib/environment.sh
index 02fb2b8..c8f27ba 100644
--- a/lib/environment.sh
+++ b/lib/environment.sh
@@ -154,6 +154,7 @@ debci_lock_dir=${debci_lock_dir:-/var/lock}
# per-suite/architecture lock/timestamp files
debci_testbed_lock=${debci_lock_dir}/debci-testbed-${debci_suite}-${debci_arch}-${debci_backend}.lock
debci_testbed_timestamp=${debci_lock_dir}/debci-testbed-${debci_suite}-${debci_arch}-${debci_backend}.stamp
+debci_testbed_setup_progress_timestamp=${debci_testbed_timestamp}.progress
debci_chdist_lock=${debci_lock_dir}/debci-chdist-${debci_suite}-${debci_arch}.lock
debci_batch_lock=${debci_lock_dir}/debci-batch-${debci_suite}-${debci_arch}.lock
diff --git a/lib/functions.sh b/lib/functions.sh
index 9d1b9e7..dc6a371 100644
--- a/lib/functions.sh
+++ b/lib/functions.sh
@@ -166,3 +166,9 @@ run_with_exclusive_lock() {
ensure_lockfile "$lockfile"
flock --exclusive "$lockfile" "$@"
}
+
+remove_testbed_setup_progress_timestamp() {
+ if [ -e "$debci_testbed_setup_progress_timestamp" ]; then
+ rm "$debci_testbed_setup_progress_timestamp"
+ fi
+}
--
2.1.4
Reply to: