feat: Improve shutdown

* feat: Improve shutdown
This commit is contained in:
Kroese
2023-12-10 15:58:37 +01:00
committed by GitHub
parent b9f3e52ba4
commit 26d6fa9fcc
3 changed files with 36 additions and 11 deletions

View File

@@ -1,16 +1,22 @@
#!/usr/bin/env bash
set -Eeuo pipefail
[ ! -f "/run/qemu.pid" ] && echo "QEMU not running yet.." && exit 0
[ -f "/run/qemu.count" ] && echo "QEMU is shutting down.." && exit 1
file="/run/dsm.url"
active="/run/qemu.pid"
shutdown="/run/qemu.count"
active_msg="QEMU not running yet.."
shutdown_msg="QEMU is shutting down.."
url="http://127.0.0.1:2210/read?command=10"
[ ! -f "$active" ] && echo "$active_msg" && exit 0
[ -f "$shutdown" ] && echo "$shutdown_msg" && exit 1
if [ ! -f "$file" ]; then
# Retrieve IP from guest VM for Docker healthcheck
{ json=$(curl -m 20 -sk "$url"); rc=$?; } || :
[ -f "$shutdown" ] && echo "$shutdown_msg" && exit 1
(( rc != 0 )) && echo "Failed to connect to guest: curl error $rc" && exit 1
{ result=$(echo "$json" | jq -r '.status'); rc=$?; } || :
@@ -36,11 +42,13 @@ if [ ! -f "$file" ]; then
fi
[ -f "$shutdown" ] && echo "$shutdown_msg" && exit 1
location=$(cat "$file")
if ! curl -m 20 -ILfSs "http://$location/" > /dev/null; then
echo "Failed to reach http://$location"
exit 1
[ -f "$shutdown" ] && echo "$shutdown_msg" && exit 1
echo "Failed to reach page at http://$location" && exit 1
fi
echo "Healthcheck OK"