You've successfully subscribed to Tech news and tutorials for and by DevOps | Kopax
Great! Next, complete checkout for full access to Tech news and tutorials for and by DevOps | Kopax
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.
How to wait for a service to be up in Bash using cURL

How to wait for a service to be up in Bash using cURL

> 1 min read

This happened to me in a CI process before where I had to configure multiple process and wait for them to be up.

The following bash script will wait for the service running at service:8000 to be up before continuing:

found_message_in_a_bottle() {
 curl --connect-timeout 2 -s service:8000 2>/dev/null| grep -q Welcome
}
wait_for_saltmaster() {
 while ! found_message_in_a_bottle; do
   echo wait for service... 
   sleep 1
 done
}

Now run wait_for_saltmaster and the CI will hang until the service is up.