aboutsummaryrefslogtreecommitdiff
path: root/buildos
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-03-31 15:51:48 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-03-31 15:51:48 +0200
commitb304f7b1c52550fef0d0a116e0155f247c16141c (patch)
tree33c06f702541a8a58f2dbe5138ab88eaa0facddc /buildos
parent5461c13bdcace38ce40494acde0e21d2cb3c9081 (diff)
Establish build machine layout
Diffstat (limited to 'buildos')
-rwxr-xr-xbuildos125
1 files changed, 124 insertions, 1 deletions
diff --git a/buildos b/buildos
index 7aa9a0e..ec2be0b 100755
--- a/buildos
+++ b/buildos
@@ -14,7 +14,8 @@
#
owd="$(pwd)"
trap "{ cd '$owd'; exit 1; }" ERR
-set -o errtrace # Trap in functions.
+set -o errtrace # Trap in functions.
+shopt -s nullglob # Expand patterns than don't match to empty.
# Note: diagnostics goes to stdout.
#
@@ -320,6 +321,128 @@ if [ -z "$tc" ]; then
info "no buildos.toolchain_url specified, not bootstrapping"
fi
+# Cleanup /build/machines/ of any stray snapshots or deleted machines.
+#
+diag=()
+fail=
+for v in /build/machines/*; do
+ if [ ! -d "$v" ]; then
+ diag+=("$v: error: invalid volume")
+ fail="true"
+ continue
+ fi
+
+ cd "$v"
+
+ for m in *; do
+ if [ ! -d "$m" ]; then
+ diag+=("$v/$m: error: invalid machine")
+ fail="true"
+ continue
+ fi
+
+ cd "$m"
+
+ # If there is no current machine symlink, then delete the whole thing.
+ #
+ d=
+ if [ ! -L "$m" ]; then
+ d="true"
+ fi
+
+ # Examine each machine subvolume.
+ #
+ for s in "$m"-*; do
+ if [ ! -d "$s" ]; then
+ diag+=("$v/$m/$s: error: invalid machine subvolume")
+ fail="true"
+ continue
+ fi
+
+ # Unless we are deleting the whole thing, keep initial and bootstrapped
+ # (for known toolchains) subvolumes.
+ #
+ if [ -z "$d" ]; then
+ # <name>-<N>
+ #
+ if [[ "$s" =~ ^"$m"-[0-9]+$ ]]; then
+ continue
+ fi
+
+ # <name>-<toolchain>
+ #
+ f=
+ for tn in "${!toolchains[@]}"; do
+ if [[ "$s" =~ ^"$m"-"$tn"$ ]]; then
+ f="true"
+ break
+ fi
+ done
+
+ if [ -n "$f" ]; then
+ continue
+ fi
+ fi
+
+ # This is either a stray working submodule or a bootsrapped subvolume
+ # for a toolchain that was deleted (or we are deleting everything).
+ #
+ if ! btrfs property set -ts "$s" ro false; then
+ diag+=("$v/$m/$s: error: unable to change subvolume property")
+ fail="true"
+ continue
+ fi
+
+ if ! btrfs subvolume delete "$s"; then
+ diag+=("$v/$m/$s: error: unable to delete subvolume")
+ fail="true"
+ continue
+ fi
+
+ diag+=("$v/$m/$s: info: deleted subvolume")
+ done
+
+ cd "$v"
+
+ # Delete the machine directory (which we expect to be now empty).
+ #
+ if [ -n "$d" ]; then
+ if ! rmdir "$m"; then
+ diag+=("$v/$m: error: unable to delete machine directory")
+ fail="true"
+ continue
+ fi
+
+ diag+=("$v/$m: info: deleted machine directory")
+ fi
+ done
+ cd "$owd"
+done
+
+function print_diag ()
+{
+ local p
+ for p in "${diag[@]}"; do
+ echo " $p"
+ done
+}
+
+if [ "${#diag[@]}" -gt 0 ]; then
+ if [ -z "$fail" ]; then
+ s="cleaned up entries in /build/machines/"
+ else
+ s="invalid entries in /build/machines/, halting"
+ fi
+
+ print_diag | email "$s"
+ info "$s" && print_diag 2>&1
+
+ if [ -n "$fail" ]; then
+ info "correct and restart the monitor (systemctl restart buildos)"
+ exit 1
+ fi
+fi
+
# Monitoring loop.
#
while true; do