Skip to content

Instantly share code, notes, and snippets.

@JensRantil
Created January 4, 2017 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JensRantil/1576cc7b7e33cb8d9e0c0d582323544f to your computer and use it in GitHub Desktop.
Save JensRantil/1576cc7b7e33cb8d9e0c0d582323544f to your computer and use it in GitHub Desktop.
Elasticsearch upstart sample for safe shutdown (for unattended security updates etc.)
description "Elastic Search"
pre-stop script
triesleft=3600
while true
do
curl -s localhost:9200/_cluster/health?pretty | grep status | grep green > /dev/null
exitcode=$?
#echo $exitcode
if [ $exitcode -ne 0 ]
then
echo "Status is not green."
sleep 10
else
echo "Status is green."
break
fi
triesleft=$((triesleft-1))
if [ $triesleft -eq 0 ]
then
echo "Tried for an hour. Restarting anyway."
break
fi
done
end script
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment