aboutsummaryrefslogtreecommitdiff
path: root/etc/private/vm-stop
blob: d3b833019afbb6656b0fc8c3bdf3949fb8fab226 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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