Skip to content

Instantly share code, notes, and snippets.

@aashreys
Created July 21, 2017 02:39
Show Gist options
  • Save aashreys/c2102814ac599dc788a20577b5383f64 to your computer and use it in GitHub Desktop.
Save aashreys/c2102814ac599dc788a20577b5383f64 to your computer and use it in GitHub Desktop.
A bash script which checks the status of a web server before executing commands.
#!/bin/bash
# wait-for-nlu.sh
set -e
host="$1"
shift
cmd="$@"
http_status="$(curl -s -o /dev/null -I -w "%{http_code}" http://www.webserver.com:8080/)"
while [ $http_status -ne 200 ]
do
>&2 echo "NLU service is unavailable - sleeping"
sleep 10
http_status=http_status
done
>&2 echo "NLU service is up - executing command"
exec $cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment