aboutsummaryrefslogtreecommitdiff
path: root/etc/private/vm-stop
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-09-03 11:44:20 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-09-03 11:47:33 +0200
commitf42eb41a5164780ac8bf5934d0fa6278a6ace6f0 (patch)
tree5dceec3319616297a8100961f83545096716627d /etc/private/vm-stop
parent35c888632c7cfa8a2c2c3995c79277dd43a179af (diff)
Initial support for private brep instance setup
Diffstat (limited to 'etc/private/vm-stop')
-rwxr-xr-xetc/private/vm-stop24
1 files changed, 24 insertions, 0 deletions
diff --git a/etc/private/vm-stop b/etc/private/vm-stop
new file mode 100755
index 0000000..d3b8330
--- /dev/null
+++ b/etc/private/vm-stop
@@ -0,0 +1,24 @@
+#! /usr/bin/env bash
+
+# Stop virtual machine started with vm-start.
+#
+usage="usage: $0 <monitor-socket>"
+
+owd="$(pwd)"
+trap "{ cd '$owd'; 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"
+fi
+
+echo system_powerdown | socat - "UNIX-CONNECT:$mon" >/dev/null
+
+# Wait for QEMU to close the socket. This is racy so ignore errors.
+#
+socat "UNIX-CONNECT:$mon" - >/dev/null 2>&1 || true