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