• Stars
    star
    102
  • Rank 335,584 (Top 7 %)
  • Language
    Shell
  • Created over 11 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Let's Make DNS Outage Suck Less

nsfailover

Build Status Gittip donate button Flattr donate button PayPayl donate button BitCoin donate button

Together with EC2 Premium support I've established that:

"Unfortunately the Linux DNS resolver doesn't seem to have direct support for detecting and doing failovers for DNS servers so you may need to write your own solution as you mentioned. " - Amazon Web Services Jan 22, 2013 01:13 AM PST

Read a longer introduction on my blog which was featured on Hacker News.

This simple program makes DNS outages suck less.

nsfailover

Every minute (or whatever), nsfailover.sh checks to see if the primary configured nameserver can resolve google.com. If it cannot, it writes the secondary, or even tertary server to function as the primary server in /etc/resolv.conf.

This way, requests are stalled for max a minute, and then all following requests are fast, even if the primary stays down.

Install

sudo curl -q https://raw.github.com/kvz/nsfailover/master/nsfailover.sh -o /usr/bin/nsfailover.sh && sudo chmod +x $_

Example

crontab -e
* * * * * NS_1=172.16.0.23 nsfailover.sh 2>&1 |logger -t cron-nsfailover

Config

nsfailover is configured through environment variables. Here they are with their defaults:

LOG_LEVEL="6" # 7 = debug, 0 = emergency
NS_1="" # Primary Nameserver (172.16.0.23 for Amazon EC2). You need to set this yourself
NS_2="8.8.8.8" # Secundary Nameserver: Google
NS_3="4.2.2.2" # Tertiary Nameserver: Level3
NS_ATTEMPTS="1" # http://linux.die.net/man/5/resolv.conf
NS_ENABLE="no" # Set to no to disable
NS_FILE="/etc/resolv.conf" # Where to write resolving conf
NS_SEARCH="" # Domain to search hosts in (compute-1.internal for Amazon EC2)
NS_TESTDOMAIN="google.com" # Use this to determine if NS is healthy
NS_TIMEOUT="3" # http://linux.die.net/man/5/resolv.conf
NS_WRITEPROTECT="no" # Use this to write-protect /etc/resolv.conf

You can use environment variables in many ways: at the top of a script or crontab, export from another script, or pass them straight to the program:

NS_ENABLE="no" ./nsfailover.sh # <-- silly, but works :)

Notes

nsfailover

  • only rewrites /etc/resolv.conf if it has changes
  • makes a backup to e.g. /etc/resolv.conf.bak-20130327114321
  • needs to run as root

Tips

  • Prefix your cronjob with timeout -s 9 50s so there can never be an overlap. More tips in my Lock your Cronjobs article.

Versioning

This project implements the Semantic Versioning guidelines.

Releases will be numbered with the following format:

<major>.<minor>.<patch>

And constructed with the following guidelines:

  • Breaking backward compatibility bumps the major (and resets the minor and patch)
  • New additions without breaking backward compatibility bumps the minor (and resets the patch)
  • Bug fixes and misc changes bumps the patch

For more information on SemVer, please visit http://semver.org.

License

Copyright (c) 2013 Kevin van Zonneveld, http://kvz.io
Licensed under MIT: http://kvz.io/licenses/LICENSE-MIT

More Repositories

1

bash3boilerplate

Templates to write better Bash scripts
Shell
2,092
star
2

json2hcl

Convert JSON to HCL, and vice versa. We don't use json2hcl anymore ourselves, so we can't invest time into it. However, we're still welcoming PRs.
HCL
504
star
3

cronlock

cronlock lets you deploy cronjobs cluster-wide without worrying about overlaps. It uses Redis to keep track of locks.
Shell
268
star
4

system_daemon

Discontinued. All the boilerplate required to daemonize php
PHP
143
star
5

ochtra

One Commit Hook To Rule All
Shell
85
star
6

invig

🌿 Invig automatically converts ES5 & CoffeeScript codebases to ES6 with Aligned JavaScript Standard Style
JavaScript
62
star
7

metriks

[UNMAINTAINED] A lightweight server graphing framework
JavaScript
56
star
8

cakephp-elasticsearch-plugin

Discontinued. CakePHP plugin for Elasticsearch: the Open Source, Distributed, RESTful, Search Engine
PHP
45
star
9

logstreamer

Prefixes streams (e.g. stdout or stderr) in Go
Go
45
star
10

fakefile

The Universal Makefile for JavaScript
JavaScript
41
star
11

lanyon

Deprecated
JavaScript
35
star
12

eventcache

Discontinued. PHP caching & invalidation for the lazy coder
PHP
15
star
13

airbud

Retrieving stuff from the web is unreliable. Airbud adds retries for production, and fixture support for test.
CoffeeScript
15
star
14

environmental

Node project that aims to provide code and conventions to deal with environment vars for configuration in a structured, reusable, pleasant way
JavaScript
13
star
15

packing-list

An MIT Licensed packing list for short trips abroad
12
star
16

deprecated

My deprecated repositories are now separate branches in this repository
12
star
17

on-the-githubs

Aggregates GitHub community activity as seen on http://tus.io and http://uppy.io .
JavaScript
11
star
18

rotation

Generate filenames suitable for backup rotation
JavaScript
9
star
19

node-depurar

Node.js debugging for the truly lazy
CoffeeScript
7
star
20

youtube-id

PHP
5
star
21

ec2-instances-list

Compare all EC2 instances in one sortable table
CSS
5
star
22

baseamp

Convert your Markdown todo lists to Basecamp Todolists and back
CoffeeScript
4
star
23

scrolex

Execute commands, scroll back the stdout & stderr, prefix by user-defined categories
JavaScript
4
star
24

riak-formation

Create/restore a riak cluster on any cloudprovider using Terraform
Shell
3
star
25

cakephp-ipv6-plugin

Discontinued. Plugin-wrapped CakePHP behavior to work with IPv6 addresses with efficient MySQL storage
PHP
3
star
26

huemidoro

Turns all your Philips HUE lamps red when it's time for a break :)
CoffeeScript
3
star
27

ratestate

A ratelimiter that can transmit states of different entities while avoiding transmitting the same state twice, and adhering to a global speed limit.
CoffeeScript
3
star
28

dialout

☎️➡️
JavaScript
2
star
29

x264

C
1
star
30

sledge

🔨
CoffeeScript
1
star
31

jekyll-fix-titlecase

Fixes title casing in markdown blogposts. Uppercases all words except for code, abbreviations, 'and', 'the', 'a', etc.
JavaScript
1
star