Skip to content

Instantly share code, notes, and snippets.

View byteshiva's full-sized avatar
🎯
Focusing

Siva byteshiva

🎯
Focusing
View GitHub Profile
@byteshiva
byteshiva / install-consul.sh
Created August 24, 2016 13:05 — forked from cbednarski/install-consul.sh
Ubuntu installer script for consul
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",
@byteshiva
byteshiva / template.json
Created August 24, 2016 13:07 — forked from d-smith/template.json
cloudformation template lab 3
{
"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"
@byteshiva
byteshiva / consul.json
Created August 24, 2016 13:07
Run with: consul agent -config-file=/opt/consul/config/config.json
{
"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%
Generate your DNS records
./route53-asg-rrdns.sh consul-asg-123
Verify your SRV record
./verify-srv.sh consul-server
@byteshiva
byteshiva / hooks_health_check.sh
Created August 24, 2016 13:09
Plan to configure Consul with habitat.
#!/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
@byteshiva
byteshiva / backup_webservice.json
Created August 24, 2016 13:11 — forked from muresan/backup_webservice.json
Backup-like feature implemented using consul. cdnhealth.json and webservice.json is on all CDN members which are not backup and backup_webservice.json is on the backup(s)
{
"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
@byteshiva
byteshiva / fire_consul_event.sh
Created August 24, 2016 13:32 — forked from ianblenke/fire_consul_event.sh
Firing consul events
#!/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"
}