Skip to content

Instantly share code, notes, and snippets.

@jeffnelson
Created February 2, 2018 17:35
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 jeffnelson/26116dfd26cba5cf78b10e236888d353 to your computer and use it in GitHub Desktop.
Save jeffnelson/26116dfd26cba5cf78b10e236888d353 to your computer and use it in GitHub Desktop.
simple bash script to loop, pinging spinnaker services' health endpoints, until all report healthy
#!/bin/bash
#####
## Helper script to use when we need to restart/redeploy spinnaker due to config changes or some other reason.
##
## This script has been written for a local debian install of spinnaker (all services running on the same box), but could be adapted fairly easily for a distributed install
##
## Steps:
## - ping health endpoints for all services every 2 seconds, reporting status of each each iteration, until all report healthy
#####
function jsonValue() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
}
main() {
services=(
'gate'
'clouddriver'
'fiat'
'echo'
'front50'
'igor'
'orca'
'rosco'
)
health=(
'https://localhost:8084/health'
'http://localhost:7002/health'
'http://localhost:7003/health'
'http://localhost:8089/health'
'http://localhost:8080/health'
'http://localhost:8088/health'
'http://localhost:8083/health'
'http://localhost:8087/health'
)
unhealthyServices=1
while [ $unhealthyServices -gt 0 ]; do
unhealthyServices=0
sleep 4s # wait 4 seconds before trying
for (( i = 0; i < ${#services[@]}; ++i )); do
status=`curl -k -s -X GET ${health[$i]} | jsonValue status 1`
status=`[[ -z "$status" ]] && echo "DOWN" || echo "$status"`
echo "service: ${services[$i]} status: $status"
if [[ $status != *"UP"* ]];
then
unhealthyServices=$[unhealthyServices + 1]
fi
done
echo "Unhealthy services: $unhealthyServices"
done
exit 0
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment