aboutsummaryrefslogtreecommitdiff
path: root/etc/private/vm-stop
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/private/vm-stop
parent1a4a071568116f1131507f692f5618d5e5748b71 (diff)
Updates to private install infrastructure and instructions
Diffstat (limited to 'etc/private/vm-stop')
-rwxr-xr-xetc/private/vm-stop29
1 files changed, 21 insertions, 8 deletions
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