1
1
sovereign-stack/deployment/wait_for_ip.sh

51 lines
1.3 KiB
Bash
Raw Normal View History

2023-04-07 18:02:24 +00:00
#!/bin/bash
set -e
2023-09-22 23:46:07 +00:00
INCUS_INSTANCE_NAME=
2023-04-07 18:02:24 +00:00
# grab any modifications from the command line.
for i in "$@"; do
case $i in
2023-11-30 02:33:45 +00:00
--incus-name=*)
2023-09-22 23:46:07 +00:00
INCUS_INSTANCE_NAME="${i#*=}"
2023-04-07 18:02:24 +00:00
shift
;;
*)
echo "Unexpected option: $1"
exit 1
;;
esac
done
# if the invoker did not set the instance name, throw an error.
2023-09-22 23:46:07 +00:00
if [ -z "$INCUS_INSTANCE_NAME" ]; then
echo "ERROR: The instance name was not specified. Use '--incus-name' when calling wait_for_ip.sh."
2023-04-07 18:02:24 +00:00
exit 1
fi
2023-09-22 23:46:07 +00:00
if ! incus list --format csv | grep -q "$INCUS_INSTANCE_NAME"; then
echo "ERROR: the instance '$INCUS_INSTANCE_NAME' does not exist."
2023-04-07 18:02:24 +00:00
exit 1
fi
IP_V4_ADDRESS=
while true; do
2023-09-22 23:46:07 +00:00
IP_V4_ADDRESS="$(incus list "$INCUS_INSTANCE_NAME" --format csv --columns=4 | grep enp5s0 | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')" || true
2023-04-07 18:02:24 +00:00
export IP_V4_ADDRESS="$IP_V4_ADDRESS"
if [ -n "$IP_V4_ADDRESS" ]; then
# give the machine extra time to spin up.
wait-for-it -t 300 "$IP_V4_ADDRESS:22"
break
else
sleep 1
printf '.'
fi
done
# wait for cloud-init to complet before returning.
2023-09-22 23:46:07 +00:00
while incus exec "$INCUS_INSTANCE_NAME" -- [ ! -f /var/lib/cloud/instance/boot-finished ]; do
2023-04-07 18:02:24 +00:00
sleep 1
2023-09-06 02:01:57 +00:00
done
sleep 1