./route53-asg-rrdns.sh consul-asg-123./verify-srv.sh consul-server| set -x | |
| mkdir -p /tmp/consul | |
| cd /tmp/consul | |
| # Consul Configuration File | |
| tee consul.json <<CONSULCONFIG | |
| { | |
| "bootstrap_expect": 3, | |
| "client_addr": "0.0.0.0", |
| { | |
| "AWSTemplateFormatVersion": "2010-09-09", | |
| "Description": "AWS CloudFormation template to create the needed AWS resources for Labs 3 & 4 of the ECS Microservices Bootcamp for re:Invent 2015", | |
| "Mappings": { | |
| "AWSRegionToAMI": { | |
| "eu-west-1": { | |
| "AMI": "ami-a10897d6" |
| { | |
| "bootstrap": false, | |
| "bootstrap_expect": 1, | |
| "datacenter": "east-aws", | |
| "data_dir": "/opt/consul/data", | |
| "log_level": "INFO", | |
| "node_name": "60f81dc58442", | |
| "server": true, | |
| "telemetry": { | |
| "dogstatsd_addr": "127.0.0.1:8125", |
| # Quick Measure | |
| grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}' | |
| # 1.37339% | |
| # Quicker | |
| top -bn1 | grep "Cpu(s)" | \ | |
| sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | \ | |
| awk '{print 100 - $1"%"}' | |
| # 1.4% |
| #!/bin/sh | |
| # | |
| # Consul Health Check for Habitat | |
| echo "health_check..." | |
| echo "" | |
| # The health_check script must return a valid exit code from the list below. | |
| # 0 - ok |
| { | |
| "services": [ | |
| { "id": "webservice-backup", | |
| "name": "webservice", | |
| "tags": ["backup"], | |
| "port": 80, | |
| "checks": [{ | |
| "name": "DNS check ", | |
| "script": "/usr/lib64/nagios/plugins/negate -s /usr/lib64/nagios/plugins/check_dns -H cdnhealth.service.cdn.example.com.", | |
| "interval": "5s", |
| #!/usr/bin/env bash | |
| set -e | |
| if [[ -e /home/core/volumes/consul/raft/peers.json ]] && [[ $(cat /home/core/volumes/consul/raft/peers.json | jq '. | length') -ge 3 ]]; then | |
| echo "CONSUL_BOOTSTRAP=\"\"" > /tmp/consul-env | |
| exit | |
| fi | |
| if [[ MACHINES=$(etcdctl ls /consul.io/machines | grep -v ${HOSTNAME}) ]] && [[ ${#MACHINES[@]} -ge 1 ]]; then | |
| for MACHINE in "$MACHINES"; do |
| #!/bin/bash | |
| consul event -name 'Name of your event' -token=$CONSUL_TOKEN 'Some payload, you should probably use JSON here' | |
| template { | |
| source = "/etc/consul/app1.json.tmpl" | |
| destination = "/var/kraken/app1.config.json" | |
| } | |
| template { | |
| source = "/etc/consul/app2.json.tmpl" | |
| destination = "/var/kraken/app2.config.json" | |
| } |