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

@@ -5,18 +5,26 @@ 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"
shutdown="/run/qemu.count"
url="http://127.0.0.1:2210/read?command=10"
while [ ! -f "$file" ]
do
# Check if not shutting down
[ -f "$shutdown" ] && exit 1
sleep 3
[ -f "$shutdown" ] && exit 1
# Healthcheck may have intervened
[ -f "$file" ] && break
# Retrieve IP from guest VM
{ json=$(curl -m 20 -sk "$url"); rc=$?; } || :
[ -f "$shutdown" ] && exit 1
(( rc != 0 )) && error "Failed to connect to guest: curl error $rc" && continue
{ result=$(echo "$json" | jq -r '.status'); rc=$?; } || :
@@ -42,6 +50,8 @@ do
done
[ -f "$shutdown" ] && exit 1
location=$(cat "$file")
if [[ "$location" != "20.20"* ]]; then