2023-04-21 08:04:53 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-04-22 17:00:13 +02:00
|
|
|
set -u
|
2023-04-21 08:04:53 +02:00
|
|
|
|
2023-05-11 02:52:25 +02:00
|
|
|
[ ! -f "/run/qemu.pid" ] && echo "QEMU not running yet.." && exit 0
|
2023-11-15 19:58:51 +01:00
|
|
|
[ -f "/run/qemu.count" ] && echo "QEMU is shutting down.." && exit 1
|
2023-05-11 02:50:45 +02:00
|
|
|
|
2023-11-15 19:58:51 +01:00
|
|
|
file="/run/dsm.url"
|
2023-04-21 08:30:00 +02:00
|
|
|
|
2023-11-15 19:58:51 +01:00
|
|
|
if [ ! -f "$file" ]; then
|
2023-05-08 18:02:13 +02:00
|
|
|
|
2023-11-15 19:58:51 +01:00
|
|
|
# Retrieve IP from guest VM for Docker healthcheck
|
|
|
|
RESPONSE=$(curl -s -m 16 -S http://127.0.0.1:2210/read?command=10 2>&1)
|
2023-05-08 18:02:13 +02:00
|
|
|
|
2023-11-15 19:58:51 +01:00
|
|
|
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
|
|
|
|
echo "Failed to connect to guest: $RESPONSE" && exit 1
|
|
|
|
fi
|
2023-05-08 18:02:13 +02:00
|
|
|
|
2023-11-15 19:58:51 +01:00
|
|
|
# Retrieve the HTTP port number
|
|
|
|
if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then
|
|
|
|
echo "Failed to parse response from guest: $RESPONSE" && exit 1
|
|
|
|
fi
|
2023-05-11 16:23:59 +02:00
|
|
|
|
2023-11-15 19:58:51 +01:00
|
|
|
rest=${RESPONSE#*http_port}
|
|
|
|
rest=${rest#*:}
|
|
|
|
rest=${rest%%,*}
|
|
|
|
PORT=${rest%%\"*}
|
|
|
|
|
|
|
|
[ -z "${PORT}" ] && echo "Guest has not set a portnumber yet.." && exit 1
|
|
|
|
|
|
|
|
# Retrieve the IP address
|
|
|
|
if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then
|
|
|
|
echo "Failed to parse response from guest: $RESPONSE" && exit 1
|
|
|
|
fi
|
2023-04-21 08:37:39 +02:00
|
|
|
|
2023-11-15 19:58:51 +01:00
|
|
|
rest=${RESPONSE#*eth0}
|
|
|
|
rest=${rest#*ip}
|
|
|
|
rest=${rest#*:}
|
|
|
|
rest=${rest#*\"}
|
|
|
|
IP=${rest%%\"*}
|
|
|
|
|
|
|
|
[ -z "${IP}" ] && echo "Guest has not received an IP yet.." && exit 1
|
|
|
|
|
|
|
|
echo "${IP}:${PORT}" > $file
|
|
|
|
|
|
|
|
fi
|
2023-05-08 18:02:13 +02:00
|
|
|
|
2023-11-15 19:58:51 +01:00
|
|
|
LOCATION=$(cat "$file")
|
2023-05-08 19:43:31 +02:00
|
|
|
|
2023-11-15 19:58:51 +01:00
|
|
|
if ! curl -m 20 -ILfSs "http://${LOCATION}/" > /dev/null; then
|
|
|
|
rm -f $file
|
|
|
|
echo "Failed to reach http://${LOCATION}"
|
2023-04-21 08:19:19 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-11-15 19:58:51 +01:00
|
|
|
if [[ "$LOCATION" == "20.20"* ]]; then
|
2023-05-11 17:17:02 +02:00
|
|
|
echo "Healthcheck OK"
|
|
|
|
else
|
2023-11-15 19:58:51 +01:00
|
|
|
echo "Healthcheck OK ( ${LOCATION%:*} )"
|
2023-05-11 17:17:02 +02:00
|
|
|
fi
|
|
|
|
|
2023-04-21 08:04:53 +02:00
|
|
|
exit 0
|