Commit dafd703d authored by Maarten de Waard's avatar Maarten de Waard 🤘🏻

add function that waits for API to be up

parent 394e7538
......@@ -464,3 +464,21 @@ mount_bottom()
{
:
}
# Ping a specified URL until you get connection or the timeout is passed
# $1=the URL to ping
# $2=timeout in seconds
# returns 0 if ping succeeds, 1 otherwise
wait_for_connection()
{
url=$1
timeout=$2
for i in 1 .. $2
do
ping -W 1 $url -c 1
if [ $? -eq 0 ]; then
return 0
fi
done
return 1
}
......@@ -104,6 +104,13 @@ setup_mapping()
notify_command="curl -X POST -H \"Authorization: Bearer $api_key\" -H \"Content-Type: application/json\" -d '{\"template\":\"ENCVMBOOTED\",\"HOSTNAME\":\"$(hostname)\",\"identifier\":\"instance-$instance_id\"}' $cosmos_url/api/v2/communication/sendmessage"
timeout=6
# Wait until API is reachable (network interface = up)
wait_for_connection $cosmos_url $timeout
# Start cryptops API even if API is not reachable, because the only problem
# is the user would not get notified of startup.
cryptops-api --root-device="$rootdevice" --crypt-name="$crypttarget" --notify-command="$notify_command"
#FSTYPE=''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment