Post

linux poll endpoint

linux poll endpoint

I use this pattern in deployment scripts to wait for a service to come up before proceeding. The while true loop with a sleep keeps checking until the endpoint responds. The curl version gives you the HTTP status code which lets you check for a specific response rather than just connectivity.

  • Poll an endpoint

Using linux terminal we can poll an endpoint by using combination of while loop with wget or curl.

We cak ignore the output and print only header

  • Poll an endpoint using wget
1
$ while true; do wget -S -O /dev/null -q https://test_website.com; echo "running"; sleep 1; done
  • Poll an endpoint using curl

you can filter header

1
$ while true; do curl --insecure --write-out '%{http_code}' --silent --output /dev/null https://test_website.com; echo "running"; sleep 1; done

you can even request server to send headers only

curl –insecure HEAD -I –silent –output /dev/null

1
$ while true; do curl --insecure HEAD -I --silent --output /dev/null https://test_website.com; echo "running"; sleep 1; done
This post is licensed under CC BY 4.0 by the author.