Last active
August 29, 2015 14:15
-
-
Save inokappa/55f917ef7a7221c15c9e to your computer and use it in GitHub Desktop.
consul watch で利用する監視スクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
とりあえずやっつけスクリプト。