Unverified Commit b9f3e52b authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Improve shutdown (#448)

* feat: Improve shutdown
parent 03d26657
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -20,4 +20,4 @@ services:
        volumes:
            - /opt/dsm:/storage
        restart: on-failure
        stop_grace_period: 1m
        stop_grace_period: 2m
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ services:
    volumes:
      - /opt/dsm:/storage
    restart: on-failure
    stop_grace_period: 1m
    stop_grace_period: 2m
```

Via `docker run`
+2 −2
Original line number Diff line number Diff line
@@ -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=$?; } || :
+4 −0
Original line number Diff line number Diff line
@@ -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

+5 −2
Original line number Diff line number Diff line
@@ -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
}
Loading