aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/manual.cli23
-rwxr-xr-xremove-machine95
2 files changed, 110 insertions, 8 deletions
diff --git a/doc/manual.cli b/doc/manual.cli
index abccb8b..91dc68b 100644
--- a/doc/manual.cli
+++ b/doc/manual.cli
@@ -457,7 +457,7 @@ the \c{build2} toolchain inside.
The \c{<name>-<toolchain>-<xxx>} entries are the temporary snapshots of
\c{<name>-<toolchain>} created by \c{bbot} for building packages.
-A machine can be added, upgraded, or deleted on a live Build OS instance.
+A machine can be added, upgraded, or removed on a live Build OS instance.
This needs to be done in a particular order to avoid inconsistencies and race
conditions.
@@ -493,6 +493,9 @@ build$ btrfs property set -ts linux-gcc_6-1.0 ro true
build$ ln -s linux-gcc_6-1.0 linux-gcc_6-1
\
+\N|The \c{upload-machine} helper script implements this sequence of steps.|
+
+
\h#machines-upgade|Upgrading a Machine|
Continuing with the example started in the previous section, let's assume we
@@ -526,43 +529,47 @@ build$ btrfs property set -ts linux-gcc_6-1.0 ro false
build$ btrfs subvolume delete linux-gcc_6-1.0
\
-\h#machines-delete|Deleting a Machine|
+\N|The \c{upload-machine} helper script implements this sequence of steps.|
+
+\h#machines-remove|Remove a Machine|
Continuing with the example started in the previous section, let's assume we
are no longer interested in the \c{linux-gcc_6} machine and would like to
-delete it. This operation is complicated by the possibility of \c{bbot}
+remove it. This operation is complicated by the possibility of \c{bbot}
instances currently building with this machine.
\
build$ cd /build/machines/default/linux-gcc_6
-# Delete the current machine symlink.
+# Remove the current machine symlink.
#
build$ rm linux-gcc_6-1
# Wait for all the linux-gcc_6-<toolchain>-<xxx> subvolumes
# to disappear.
#
-build$ for d in linux-gcc_6-*-*; do \
+build$ for d in linux-gcc_6-*-*/; do \
while [ -d $d ]; do \
echo \"waiting for $d\" && \
sleep 10; \
done; \
done
-# Delete the initial and bootstrapped machine subvolume(s).
+# Remove the initial and bootstrapped machine subvolume(s).
#
-build$ for d in linux-gcc_6-*; do \
+build$ for d in linux-gcc_6-*/; do \
btrfs property set -ts $d ro false && \
btrfs subvolume delete $d; \
done
-# Delete the machine directory.
+# Remove the machine directory.
#
build$ cd ..
build$ rmdir /build/machines/default/linux-gcc_6
\
+\N|The \c{remove-machine} helper script implements this sequence of steps.|
+
Note also that on reboot the Build OS monitor examines and cleans up
machine directories of any stray subvolumes. As a result, an alternative
approach would be to remove the current machine symlink and reboot the
diff --git a/remove-machine b/remove-machine
new file mode 100755
index 0000000..71c1fc1
--- /dev/null
+++ b/remove-machine
@@ -0,0 +1,95 @@
+#! /usr/bin/env bash
+
+# Remove machine from a Build OS build host.
+#
+# Note that this removes the entire machine directory with all the subvolumes,
+# etc., rather than a specific machine subvolume.
+#
+# <host> - build host to upload to (as user 'build')
+# <machine> - machine name including version
+#
+usage="usage: $0 <host> <machine>"
+
+machines=/build/machines/default
+
+owd="$(pwd)"
+trap "{ cd '$owd'; exit 1; }" ERR
+set -o errtrace # Trap in functions.
+
+function info () { echo "$*" 1>&2; }
+function error () { info "$*"; exit 1; }
+
+while [ "$#" -gt 0 ]; do
+ case "$1" in
+ -*)
+ error "unknown option: $1"
+ ;;
+ *)
+ break
+ ;;
+ esac
+done
+
+host="$1"
+machine="${2%/}"
+
+if [ -z "$host" -o -z "$machine" ]; then
+ error "$usage"
+fi
+
+# Get the machine link (<name>-<P>) and name.
+#
+mlink="$(sed -n -re 's/^(.+-[0-9]+)\.[0-9]+$/\1/p' <<<"$machine")"
+mname="$(sed -n -re 's/^(.+)-[0-9]+$/\1/p' <<<"$mlink")"
+
+if [ -z "$mlink" -o -z "$mname" ]; then
+ error "unable to extract machine link/name from '$machine'"
+fi
+
+host="build@$host"
+
+# Make sure the machine exists.
+#
+if ! ssh "$host" test -d "$machines/$mname"; then
+ error "$machines/$mname does not exist on $host"
+fi
+
+set -x
+
+# Remove the current machine symlink, if any.
+#
+ssh "$host" rm -f "$machines/$mname/$mlink"
+
+# Wait for all the <name>-<toolchain>-<xxx> subvolumes to disappear.
+#
+{ set +x; } 2>/dev/null
+
+sv=($(ssh "$host" "shopt -s nullglob; echo $machines/$mname/$mname-*-*/"))
+
+for d in "${sv[@]}"; do
+ while ssh "$host" test -d "$d"; do
+ echo "waiting for $d to disappear..."
+ sleep 10
+ done
+done
+
+set -x
+
+# Remove the initial and bootstrapped machine subvolume(s).
+#
+{ set +x; } 2>/dev/null
+
+sv=($(ssh "$host" "shopt -s nullglob; echo $machines/$mname/$mname-*/"))
+
+for d in "${sv[@]}"; do
+ set -x
+ ssh "$host" btrfs property set -ts "$d" ro false
+ ssh "$host" btrfs subvolume delete "$d"
+ { set +x; } 2>/dev/null
+done
+
+set -x
+
+# Finally remove the machine directory (which should be empty).
+#
+ssh "$host" rmdir "$machines/$mname"