Skip to content

Instantly share code, notes, and snippets.

@inokappa
Last active August 29, 2015 14:15
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 inokappa/55f917ef7a7221c15c9e to your computer and use it in GitHub Desktop.
Save inokappa/55f917ef7a7221c15c9e to your computer and use it in GitHub Desktop.
consul watch で利用する監視スクリプト
#!/bin/sh
TAG_LEADER_ID=`aws --region ap-northeast-1 ec2 describe-instances --query 'Reservations[].Instances[].InstanceId' --output text --filter 'Name=tag:consul-leader,Values=true'`
CUR_LEADER_IP=`curl -s -X GET http://localhost:8500/v1/status/leader | sed 's/\:8300//g'`
CUR_LEADER_ID=`aws --region ap-northeast-1 ec2 describe-instances --query 'Reservations[].Instances[].InstanceId' --output text --filter "Name=private-ip-address,Values=${CUR_LEADER_IP}"`
#echo $TAG_LEADER_ID
#echo $CUR_LEADER_IP
#echo $CUR_LEADER_ID
if [ $TAG_LEADER_ID = $CUR_LEADER_ID ];then
logger -t consul-watcher "consul leader node $TAG_LEADER_ID = $CUR_LEADER_ID"
else
logger -t consul-watcher "update tag to $CUR_LEADER_ID"
aws --region ap-northeast-1 ec2 create-tags --resources ${TAG_LEADER_ID} --tags Key=consul-leader,Value=
aws --region ap-northeast-1 ec2 create-tags --resources ${CUR_LEADER_ID} --tags Key=consul-leader,Value=true
fi
@inokappa
Copy link
Author

とりあえずやっつけスクリプト。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment