Last active
October 13, 2018 23:12
-
-
Save sators/111faf88ba7bdb080f804eea701c4ed6 to your computer and use it in GitHub Desktop.
Bash script to join a rabbitmq cluster of the same AWS autoscaling group
This file contains hidden or 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/bash | |
wget --quiet http://s3.amazonaws.com/ec2metadata/ec2-metadata | |
sudo chmod u+x ec2-metadata | |
INSTANCE_ID=$(./ec2-metadata | grep instance-id | awk 'NR==1{print $2}') | |
AG_NAME=$(aws autoscaling describe-auto-scaling-instances --instance-ids ${INSTANCE_ID} --query AutoScalingInstances[].AutoScalingGroupName --output text) | |
echo =================================== | |
echo Searching for cluster in ${AG_NAME} | |
echo =================================== | |
echo Local Instance ID: ${INSTANCE_ID} | |
for ID in $(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names ${AG_NAME} --query AutoScalingGroups[].Instances[].InstanceId --output text); | |
do | |
echo Found cluster node ${ID} | |
if [ "${ID}" == ${INSTANCE_ID} ] ; then | |
continue; | |
fi | |
DNS=$(aws ec2 describe-instances --instance-ids $ID --query Reservations[].Instances[].PrivateDnsName --output text) | |
DNS=(${DNS//./ }) | |
echo Joining cluster ${ID} at rabbit@${DNS[0]} | |
rabbitmqctl stop_app | |
rabbitmqctl join_cluster rabbit@${DNS[0]} | |
rabbitmqctl start_app | |
exit 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note this is expecting your default region for the
aws
cli to already be set: