Last active
November 22, 2016 17:57
-
-
Save kgorskowski/b8f70af69882edb4e3439611db6b8fc4 to your computer and use it in GitHub Desktop.
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 | |
| internalIP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4) | |
| instanceID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) | |
| hostname="consul-$(curl -s http://169.254.169.254/latest/meta-data/instance-id)" | |
| aws ec2 describe-instances --region eu-west-1 --filters 'Name=instance-state-name,Values=running' | jq -r '.Reservations[].Instances[].PrivateIpAddress' > /tmp/instances | |
| while read line; | |
| do | |
| if [ "$line" != "$internalIP" ]; then | |
| echo "Adding address $line" | |
| cat /etc/consul/config/000-consul.json | jq 'del(.retry_join[])' | jq 'del(.advertise_addr)' > /tmp/cleaned.json | |
| cat /tmp/cleaned.json | jq ".retry_join += [\"$line\"]" | jq ".advertise_addr += \"$internalIP\"" > /tmp/${line}-consul.json | |
| if [ -s /tmp/${line}-consul.json ]; then | |
| cp /tmp/${line}-consul.json /etc/consul/config/000-consul.json | |
| fi | |
| fi | |
| done < /tmp/instances | |
| rm -f /tmp/instances $$ rm -f /tmp/*.json | |
| rm -rf /var/consul/* |
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
| description "Consul server process" | |
| start on (local-filesystems and net-device-up IFACE=eth0) | |
| stop on runlevel [!12345] | |
| respawn | |
| setuid consul | |
| setgid consul | |
| exec consul agent -config-dir /etc/consul/config/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment