Bash - check to make sure website is available before continuing, otherwise sleep and try again

Viewed 82

I have a script that I want to execute at startup of a Linux host, but it is depending on influxdb running on another host. Since both hosts come up around the same time, I need influxdb up before I can run my script, else the script will fail.

I was thinking that it should be a bash script, that first checks if a port is available using curl. If it is, continue. If it is not, then sleep for 30 seconds and try again, and so on.

So far, I have the right logic to check if influxdb is up, but I can't figure out how to incorporate this into the bash script.

if 
  curl --head --silent --fail http://tick.home:8086/ping 1> /dev/null
    then echo "1"
  else echo "0"
fi

If the result is 1, continue with the script. If the result is 0, sleep for 30 seconds, then try the if statement again. What is the best way to accomplish?

1 Answers

try with

until curl --head --silent --fail http://tick.home:8086/ping 1> /dev/null 2>&1; do
    sleep 1
done
Related