virtual-dsm/run/check.sh

52 lines
1.1 KiB
Bash
Raw Normal View History

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-05-11 02:50:45 +02:00
2023-05-11 17:17:02 +02:00
# Retrieve IP from guest VM for Docker healthcheck
2023-05-08 22:46:59 +02:00
RESPONSE=$(curl -s -m 6 -S http://127.0.0.1:2210/read?command=10 2>&1)
2023-04-21 08:30:00 +02:00
2023-05-08 18:02:13 +02:00
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
2023-05-11 16:23:59 +02:00
echo "Failed to connect to guest: $RESPONSE" && exit 1
2023-05-08 18:02:13 +02:00
fi
# Retrieve the HTTP port number
if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then
2023-05-11 16:23:59 +02:00
echo "Failed to parse response from guest: $RESPONSE" && exit 1
2023-05-08 18:02:13 +02:00
fi
rest=${RESPONSE#*http_port}
rest=${rest#*:}
rest=${rest%%,*}
PORT=${rest%%\"*}
2023-05-11 17:17:02 +02:00
[ -z "${PORT}" ] && echo "Guest has not set a portnumber yet.." && exit 1
2023-05-11 16:23:59 +02:00
2023-05-08 18:02:13 +02:00
# Retrieve the IP address
2023-04-21 08:30:00 +02:00
2023-05-08 18:02:13 +02:00
if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then
2023-05-11 16:23:59 +02:00
echo "Failed to parse response from guest: $RESPONSE" && exit 1
2023-04-21 08:37:39 +02:00
fi
2023-05-08 18:02:13 +02:00
rest=${RESPONSE#*eth0}
rest=${rest#*ip}
rest=${rest#*:}
rest=${rest#*\"}
IP=${rest%%\"*}
2023-05-11 17:17:02 +02:00
[ -z "${IP}" ] && echo "Guest has not received an IP yet.." && exit 1
2023-05-08 19:43:31 +02:00
2023-04-21 20:58:18 +02:00
if ! curl -m 3 -ILfSs "http://${IP}:${PORT}/" > /dev/null; then
2023-04-22 20:29:41 +02:00
echo "Failed to reach ${IP}:${PORT}"
2023-04-21 08:19:19 +02:00
exit 1
fi
2023-05-11 17:17:02 +02:00
if [[ "$IP" == "20.20"* ]]; then
echo "Healthcheck OK"
else
echo "Healthcheck OK ( $IP )"
fi
2023-04-21 08:04:53 +02:00
exit 0