aboutsummaryrefslogtreecommitdiff
path: root/etc
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-09-09 15:04:52 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-09-09 15:04:52 +0200
commit25ef69650687f0fca9951bdcb16b2b3679a0601d (patch)
treeeee80b51a0a0e1c573f16cbb9c8a971000603f31 /etc
parent1a4a071568116f1131507f692f5618d5e5748b71 (diff)
Updates to private install infrastructure and instructions
Diffstat (limited to 'etc')
-rw-r--r--etc/private/README45
-rwxr-xr-xetc/private/install/brep-startup15
-rwxr-xr-xetc/private/install/vm-gen-service7
-rwxr-xr-xetc/private/vm-login3
-rwxr-xr-xetc/private/vm-start-base27
-rwxr-xr-xetc/private/vm-stop29
6 files changed, 106 insertions, 20 deletions
diff --git a/etc/private/README b/etc/private/README
index daecc6a..f59201a 100644
--- a/etc/private/README
+++ b/etc/private/README
@@ -214,7 +214,7 @@ If the VM fails to start, study the log for a possible cause:
# journalctl -u vm-brep@brep
-If the VM has started successfully, perform the same verifications as on step
+If the VM has started successfully, perform the same verifications as on Step
4 above.
To login to the VM running as a systemd service (for example, to verify IP
@@ -239,7 +239,7 @@ After this you may also want to reboot the host machine and confirm the VM is
started on boot.
-6. Managing the repository state.
+6. Manage the repository state.
While you can submit packages to the repository using bdep-publish(1), you can
also add them manually. Also, packages can only be removed manually.
@@ -263,7 +263,7 @@ Putting it all together, the steps could look like this:
# systemctl stop vm-brep@brep
# su - brep
$ cd state/bpkg/pkg
-$ ...
+$ <make your changes here>
$ rm 1/packages.manifest
$ exit
# systemctl start vm-brep@brep
@@ -278,3 +278,42 @@ $ ~/bin/vm-login ~/brep-con.sock
# systemctl status brep-startup
# journalctl -u brep-startup
+
+
+7. Upgrade the VM.
+
+To upgrade to the new version of the VM, first download and unpack the new
+VM archive similar to Step 2:
+
+$ curl -fO https://download.build2.org/X.Y.Z/linux-debian-N-brep-X.Y.Z.tar.xz
+$ sha256sum -b linux-debian-N-brep-X.Y.Z.tar.xz
+
+Verify the checksum matches the one from https://build2.org/download.xhtml
+
+$ tar -xf linux-debian-N-brep-X.Y.Z.tar.xz
+
+Next read the linux-debian-N-brep-X.Y.Z/NEWS file for changes and potential
+backwards compatibility issues. Unless instructed otherwise by the NEWS file,
+the upgrade procedure is as follows:
+
+# systemctl stop vm-brep@brep
+
+$ cd
+$ mkdir bak
+$ mv -t bak/ bin etc vm/brep.img vm-brep@.service README NEWS
+$ mv -t ./ linux-debian-N-brep-X.Y.Z/*
+$ rm state/bpkg/pkg/1/packages.manifest
+
+# cp ~brep/vm-brep@.service /etc/systemd/system/
+# chmod 644 /etc/systemd/system/vm-brep@.service
+# systemctl daemon-reload
+# systemctl start vm-brep@brep
+# systemctl status vm-brep@brep
+
+If the VM has started successfully, perform the same verifications as on Step
+4 above. If everything is functioning correctly, you can remove the backup
+files:
+
+$ rm -r bak
+
+If there are any issues, investigate as on Step 6.
diff --git a/etc/private/install/brep-startup b/etc/private/install/brep-startup
index 7a5f262..780a2c0 100755
--- a/etc/private/install/brep-startup
+++ b/etc/private/install/brep-startup
@@ -35,7 +35,20 @@ fi
r="$d/pkg/1"
if [ ! -f "$r/repositories.manifest" ]; then
- echo ": 1" >"$r/repositories.manifest"
+ cat <<EOF >"$r/repositories.manifest"
+: 1
+#summary: Private repository
+#description: \\
+#This is a private repository.
+#And this description can contain multiple lines.
+#\\
+#email: admin@example.org
+
+#:
+#role: prerequisite
+#location: https://pkg.cppget.org/1/stable
+#trust: ...
+EOF
fi
if [ ! -f "$r/packages.manifest" ]; then
diff --git a/etc/private/install/vm-gen-service b/etc/private/install/vm-gen-service
index c4938c2..ae49a49 100755
--- a/etc/private/install/vm-gen-service
+++ b/etc/private/install/vm-gen-service
@@ -180,13 +180,16 @@ ExecStart=$bin/vm-start \\
--ram \${RAM} \\
--tap \${TAP} \\
--mac \${MAC} \\
+ --pid $run/%i.pid \\
--monitor $run/%i-mon.sock \\
--console $run/%i-con.sock \\
$var/%i.img
-ExecStop=$bin/vm-stop $run/%i-mon.sock
+ExecStop=$bin/vm-stop $run/%i.pid $run/%i-mon.sock
-# Make systemd wait for ExecStop completion.
+# This makes sure systemd waits for the ExecStart command to exit rather
+# than killing it as soon as ExecStop exits (this is necessary since our
+# vm-stop may exit just before vm-start).
#
KillMode=none
TimeoutStopSec=60
diff --git a/etc/private/vm-login b/etc/private/vm-login
index 4573cba..28e8864 100755
--- a/etc/private/vm-login
+++ b/etc/private/vm-login
@@ -6,8 +6,7 @@
#
usage="usage: $0 <console-socket>"
-owd="$(pwd)"
-trap "{ cd '$owd'; exit 1; }" ERR
+trap "{ exit 1; }" ERR
set -o errtrace # Trap in functions.
function info () { echo "$*" 1>&2; }
diff --git a/etc/private/vm-start-base b/etc/private/vm-start-base
index a88ea2d..4a81661 100755
--- a/etc/private/vm-start-base
+++ b/etc/private/vm-start-base
@@ -15,6 +15,9 @@
# --mac <addr>
# MAC address to use for the machine.
#
+# --pid <path>
+# PID file path, /tmp/vm-<tap>.pid if unspecified.
+#
# --monitor <path>
# Monitor UNIX socket path, /tmp/vm-<tap>-mon.sock if unspecified.
#
@@ -22,15 +25,16 @@
# Console UNIX socket path, /tmp/vm-<tap>-con.sock if unspecified.
#
# --stdio
-# Connect both console and monitor to stdio (multiplexed).
+# Connect both console and monitor to stdio (multiplexed). This disables
+# the creation of the monitor and console sockets.
#
# --stdio-monior
-# Connect only monitor to stdio.
+# Connect only monitor to stdio. This disables the creation of the monitor
+# socket.
#
usage="usage: $0 [<options>] <vm-img> [<extra-qemu-options>]"
-owd="$(pwd)"
-trap "{ cd '$owd'; exit 1; }" ERR
+trap "{ exit 1; }" ERR
set -o errtrace # Trap in functions.
function info () { echo "$*" 1>&2; }
@@ -46,6 +50,7 @@ cpu=1
ram=2G
tap=
mac="de:ad:be:ef:b8:da"
+pid=
mon=
con=
stdio=
@@ -73,6 +78,11 @@ while [ "$#" -gt 0 ]; do
mac="$1"
shift
;;
+ --pid)
+ shift
+ pid="$1"
+ shift
+ ;;
--monitor)
shift
mon="$1"
@@ -133,6 +143,11 @@ if [ -z "$tap" ]; then
del_tap=true
fi
+if [ -z "$pid" ]; then
+ pid="/tmp/vm-$tap.pid"
+fi
+echo "$$" >"$pid"
+
if [ -z "$mon" ]; then
mon="/tmp/vm-$tap-mon.sock"
fi
@@ -182,6 +197,10 @@ fi
"${qemu[@]}" "${ops[@]}" -boot c "$@"
+if [ "$pid" -o "$mon" -o "$con" ]; then
+ rm -f "$pid" "$mon" "$con"
+fi
+
if [ "$del_tap" ]; then
sudo ip tuntap delete "$tap" mode tap
fi
diff --git a/etc/private/vm-stop b/etc/private/vm-stop
index d3b8330..cf64dee 100755
--- a/etc/private/vm-stop
+++ b/etc/private/vm-stop
@@ -2,23 +2,36 @@
# Stop virtual machine started with vm-start.
#
-usage="usage: $0 <monitor-socket>"
+usage="usage: $0 <pid-file> <monitor-socket>"
-owd="$(pwd)"
-trap "{ cd '$owd'; exit 1; }" ERR
+trap "{ exit 1; }" ERR
set -o errtrace # Trap in functions.
function info () { echo "$*" 1>&2; }
function error () { info "$*"; exit 1; }
-mon="$1"
-if [ -z "$mon" ]; then
- error "missing monitor socket"
+if [ -z "$1" -o ! -f "$1" ]; then
+ error "missing or invalid PID file"
fi
+pid="$(sed -nr -e 's/([0-9]+)/\1/p' "$1")"
+
+if [ -z "$pid" ]; then
+ error "PID file $1 does not contain valid PID"
+fi
+
+if [ -z "$2" -o ! -S "$2" ]; then
+ error "missing or invalid monitor socket"
+fi
+
+mon="$2"
+
echo system_powerdown | socat - "UNIX-CONNECT:$mon" >/dev/null
-# Wait for QEMU to close the socket. This is racy so ignore errors.
+# An alternative way to implement this would be to connect a pipe to the
+# monitor socket and wait for it to be closed.
#
-socat "UNIX-CONNECT:$mon" - >/dev/null 2>&1 || true
+while [ -e "/proc/$pid" ]; do
+ sleep 0.2
+done