virtual-dsm/run/check.sh

54 lines
1.0 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-10 03:00:38 +02:00
# Retrieve IP from guest 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
echo "Failed to connect to guest: $RESPONSE"
exit 1
fi
# Retrieve the HTTP port number
if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then
echo "Failed to parse response from guest: $RESPONSE"
exit 1
fi
rest=${RESPONSE#*http_port}
rest=${rest#*:}
rest=${rest%%,*}
PORT=${rest%%\"*}
2023-05-08 19:43:31 +02:00
if [ -z "${PORT}" ]; then
echo "Guest has not set a portnumber yet.."
exit 1
fi
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
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-08 19:43:31 +02:00
if [ -z "${IP}" ]; then
echo "Guest has not received an IP yet.."
exit 1
fi
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-10 03:00:38 +02:00
echo "Healthcheck OK ($IP)"
2023-04-21 08:04:53 +02:00
exit 0