diff --git a/docker-compose.yml b/docker-compose.yml index 4fd2476..8aef6bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,4 +20,4 @@ services: volumes: - /opt/dsm:/storage restart: on-failure - stop_grace_period: 1m + stop_grace_period: 2m diff --git a/readme.md b/readme.md index 9babfe3..03ec6b3 100644 --- a/readme.md +++ b/readme.md @@ -41,7 +41,7 @@ services: volumes: - /opt/dsm:/storage restart: on-failure - stop_grace_period: 1m + stop_grace_period: 2m ``` Via `docker run` diff --git a/src/check.sh b/src/check.sh index 5cd1386..061c495 100644 --- a/src/check.sh +++ b/src/check.sh @@ -5,12 +5,12 @@ set -Eeuo pipefail [ -f "/run/qemu.count" ] && echo "QEMU is shutting down.." && exit 1 file="/run/dsm.url" +url="http://127.0.0.1:2210/read?command=10" if [ ! -f "$file" ]; then # Retrieve IP from guest VM for Docker healthcheck - - { json=$(curl -m 30 -sk http://127.0.0.1:2210/read?command=10); rc=$?; } || : + { json=$(curl -m 20 -sk "$url"); rc=$?; } || : (( rc != 0 )) && echo "Failed to connect to guest: curl error $rc" && exit 1 { result=$(echo "$json" | jq -r '.status'); rc=$?; } || : diff --git a/src/network.sh b/src/network.sh index 345657d..eed1b52 100644 --- a/src/network.sh +++ b/src/network.sh @@ -156,11 +156,15 @@ closeNetwork () { if [[ "$DHCP" == [Yy1]* ]]; then + { pkill -f server.sh || true; } 2>/dev/null + ip link set "$VM_NET_TAP" down || true ip link delete "$VM_NET_TAP" || true else + { pkill -f dnsmasq || true; } 2>/dev/null + ip link set "$VM_NET_TAP" down promisc off || true ip link delete "$VM_NET_TAP" || true diff --git a/src/power.sh b/src/power.sh index 8c5d903..61fa332 100644 --- a/src/power.sh +++ b/src/power.sh @@ -33,11 +33,12 @@ _graceful_shutdown() { # echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_PORT}" > /dev/null # Send shutdown command to guest agent via serial port - response=$(curl -sk -m 30 -S http://127.0.0.1:2210/read?command=6 2>&1) + url="http://127.0.0.1:2210/read?command=6&timeout=50" + response=$(curl -sk -m 60 -S "$url" 2>&1) if [[ ! "$response" =~ "\"success\"" ]]; then - echo && error "Failed to send shutdown command ( $response )." + echo && error "Failed to send shutdown command (${response#*message\"\: \"})." kill -15 "$(cat "$QEMU_PID")" pkill -f qemu-system-x86_64 || true @@ -64,7 +65,9 @@ _graceful_shutdown() { echo && echo "❯ Quitting..." echo 'quit' | nc -q 1 -w 1 localhost "$QEMU_PORT" >/dev/null 2>&1 || true + pkill -f host.bin || true closeNetwork + sleep 1 return } diff --git a/src/print.sh b/src/print.sh index 8b31f0b..9285cd1 100644 --- a/src/print.sh +++ b/src/print.sh @@ -5,16 +5,18 @@ info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "$1" "\E[0m\n" >&2; } error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; } file="/run/dsm.url" - +url="http://127.0.0.1:2210/read?command=10" + while [ ! -f "$file" ] do sleep 3 - [ -f "$file" ] && continue + + # Healthcheck may have intervened + [ -f "$file" ] && break # Retrieve IP from guest VM - - { json=$(curl -m 30 -sk http://127.0.0.1:2210/read?command=10); rc=$?; } || : + { json=$(curl -m 20 -sk "$url"); rc=$?; } || : (( rc != 0 )) && error "Failed to connect to guest: curl error $rc" && continue { result=$(echo "$json" | jq -r '.status'); rc=$?; } || :