Last active
November 22, 2016 17:57
-
-
Save kgorskowski/b8f70af69882edb4e3439611db6b8fc4 to your computer and use it in GitHub Desktop.
Revisions
-
Karsten Gorskowski revised this gist
Aug 17, 2016 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,4 @@ #!/bin/bash hostname="consul-$(curl -s http://169.254.169.254/latest/meta-data/instance-id)" CONF=/etc/consul/config/000-consul.json TEMPLATE="/mnt/dashboard/consul-config/config.json" @@ -23,9 +21,10 @@ while [ -z "$(curl -s http://localhost:8500/v1/status/leader)" ] || [ "$(curl -s done if [ ! -e $TEMPLATE ] then echo "$TEMPLATE not found in time limit" >> /var/log/consul.log exit 1 fi internalIP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4) cat /mnt/dashboard/consul-config/config.json | jq ".advertise_addr += \"$internalIP\"" > /tmp/step1.json jq --slurpfile instances /tmp/instances '.retry_join=$instances' < /tmp/step1.json > $CONF stop consul -
Karsten Gorskowski revised this gist
Aug 17, 2016 . 3 changed files with 21 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,12 @@ 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)" CONF=/etc/consul/config/000-consul.json TEMPLATE="/mnt/dashboard/consul-config/config.json" x=0 rm -f $CONF rm -f /tmp/instances $$ rm -f /tmp/*.json restart consul while [ -z "$(curl -s http://localhost:8500/v1/status/leader)" ] || [ "$(curl -s http://localhost:8500/v1/status/leader)" == \"\" ]; do @@ -12,6 +17,15 @@ while [ -z "$(curl -s http://localhost:8500/v1/status/leader)" ] || [ "$(curl -s aws ec2 describe-instances --region eu-west-1 --filters 'Name=tag:Name,Values=dashing-ecs-instance' 'Name=instance-state-name,Values=running' | jq '.Reservations[].Instances[].PrivateIpAddress' > /tmp/instances sleep 10 done while [ "$x" -lt 30 ] && [ ! -e $TEMPLATE ]; do x=$((x+1)) sleep 1 done if [ ! -e $TEMPLATE ] then echo "$TEMPLATE not found in time limit" exit 1 fi cat /mnt/dashboard/consul-config/config.json | jq ".advertise_addr += \"$internalIP\"" > /tmp/step1.json jq --slurpfile instances /tmp/instances '.retry_join=$instances' < /tmp/step1.json > $CONF stop 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ start on runlevel [2345] script /usr/local/bin/bootstrap-consul end script 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,5 @@ #!/bin/bash echo ECS_CLUSTER=dashing-ecs > /etc/ecs/ecs.config sudo yum install -y nfs-utils mkdir -p /mnt/dashboard sudo mount -t nfs4 -o nfsvers=4.1 $(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).*filesystem*.efs.eu-west-1.amazonaws.com:/ /mnt/dashboard -
Karsten Gorskowski revised this gist
Aug 16, 2016 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,12 +8,12 @@ restart consul while [ -z "$(curl -s http://localhost:8500/v1/status/leader)" ] || [ "$(curl -s http://localhost:8500/v1/status/leader)" == \"\" ]; do echo "no cluster leader" while [ ! -s /tmp/instances ]; do aws ec2 describe-instances --region eu-west-1 --filters 'Name=tag:Name,Values=dashing-ecs-instance' 'Name=instance-state-name,Values=running' | jq '.Reservations[].Instances[].PrivateIpAddress' > /tmp/instances sleep 10 done cat /mnt/dashboard/consul-config/config.json | jq ".advertise_addr += \"$internalIP\"" > /tmp/step1.json jq --slurpfile instances /tmp/instances '.retry_join=$instances' < /tmp/step1.json > $CONF stop consul rm -rf /var/consul/* start consul -
Karsten Gorskowski revised this gist
Aug 16, 2016 . 1 changed file with 17 additions and 11 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,23 @@ #!/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)" CONF=/etc/consul/config/000-consul.json rm -f $CONF restart consul while [ -z "$(curl -s http://localhost:8500/v1/status/leader)" ] || [ "$(curl -s http://localhost:8500/v1/status/leader)" == \"\" ]; do echo "no cluster leader" aws ec2 describe-instances --region eu-west-1 --filters 'Name=tag:Name,Values=dashing-ecs-instance' 'Name=instance-state-name,Values=running' | jq '.Reservations[].Instances[].PrivateIpAddress' > /tmp/instances # cat /etc/consul/config/000-consul.json | jq 'del(.retry_join[])' | jq 'del(.advertise_addr)' > /tmp/cleaned.json cat /mnt/dashboard/consul-config/config.json | jq ".advertise_addr += \"$internalIP\"" > /tmp/step1.json if [ -s /tmp/instances ]; then jq --slurpfile instances /tmp/instances '.retry_join=$instances' < /tmp/step1.json > $CONF fi stop consul rm -rf /var/consul/* start consul sleep 10 done echo "Consul Cluster is healtyh, leader is $(curl -s http://localhost:8500/v1/status/leader), cleaning up" rm -f /tmp/instances $$ rm -f /tmp/*.json -
Karsten Gorskowski revised this gist
Aug 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,5 +2,5 @@ echo ECS_CLUSTER=dashing-ecs >> /etc/ecs/ecs.config sudo yum install -y nfs-utils mkdir -p /mnt/dashboard sudo mount -t nfs4 -o nfsvers=4.1 $(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).*filesystem*.efs.eu-west-1.amazonaws.com:/ /mnt/dashboard bash /usr/local/bin/consul-bootstrap -
Karsten Gorskowski revised this gist
Aug 16, 2016 . 1 changed file with 9 additions and 16 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,17 @@ #!/bin/bash stop consul 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)" CONF=/etc/consul/config/000-consul.json aws ec2 describe-instances --region eu-west-1 --filters 'Name=tag:Name,Values=dashing-ecs-instance' 'Name=instance-state-name,Values=running' | jq '.Reservations[].Instances[].PrivateIpAddress' > /tmp/instances cat /etc/consul/config/000-consul.json | jq 'del(.retry_join[])' | jq 'del(.advertise_addr)' > /tmp/cleaned.json cat /tmp/cleaned.json | jq ".advertise_addr += \"$internalIP\"" > /tmp/step1.json jq --slurpfile instances /tmp/instances '.retry_join=$instances' < /tmp/step1.json > $CONF rm -f /tmp/instances $$ rm -f /tmp/*.json rm -rf /var/consul/ start consul -
Karsten Gorskowski revised this gist
Aug 16, 2016 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ #!/bin/bash echo ECS_CLUSTER=dashing-ecs >> /etc/ecs/ecs.config sudo yum install -y nfs-utils mkdir -p /mnt/dashboard sudo mount -t nfs4 -o nfsvers=4.1 $(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).fs-beb05b77.efs.eu-west-1.amazonaws.com:/ /mnt/dashboard bash /usr/local/bin/consul-bootstrap -
Karsten Gorskowski revised this gist
Aug 16, 2016 . 1 changed file with 17 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,22 @@ description "Consul agent" start on runlevel [2345] stop on runlevel [!2345] respawn script if [ -f "/etc/service/consul" ]; then . /etc/service/consul fi # Make sure to use all our CPUs, because Consul can block a scheduler thread export GOMAXPROCS=`nproc` # Get the public IP exec /usr/local/bin/consul agent \ -config-dir="/etc/consul/config" \ ${CONSUL_FLAGS} \ >>/var/log/consul.log 2>&1 end script -
Karsten Gorskowski revised this gist
Aug 16, 2016 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ 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/ -
Karsten Gorskowski revised this gist
Aug 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -21,4 +21,4 @@ do fi done < /tmp/instances rm -f /tmp/instances $$ rm -f /tmp/*.json rm -rf /var/consul/* -
Karsten Gorskowski created this gist
Aug 16, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ #!/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/