Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Disable upstream DNS when in offline mode.
Browse files Browse the repository at this point in the history
This is to prevent DNS loops when the host and MCF are each pointing to
each other for DNS.

Change-Id: I1b3f8aa34a1b218956a126c86d39dd6751af6845
  • Loading branch information
mmb committed Oct 1, 2012
1 parent 9843d62 commit b388031
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 5 additions & 1 deletion micro/config/dnsmasq.erb
Expand Up @@ -3,7 +3,11 @@ if [ "$reason" = "BOUND" ]; then

for ns in $new_domain_name_servers
do
echo "server=$ns"
if [ -e "/var/vcap/micro/offline" ]; then
echo "# server=$ns"
else
echo "server=$ns"
fi
done > /etc/dnsmasq.d/server

service dnsmasq restart
Expand Down
28 changes: 27 additions & 1 deletion micro/lib/micro/network.rb
Expand Up @@ -3,6 +3,8 @@
require 'resolv'
require 'statemachine'
require 'timeout'
require 'fileutils'
require 'tempfile'

module VCAP
module Micro
Expand Down Expand Up @@ -154,12 +156,36 @@ def toggle_online_status
def online!
FileUtils.rm_f(OFFLINE_FILE)
FileUtils.rm_f(OFFLINE_CONF)

# Uncomment upstream DNS servers in /etc/dnsmasq.d/server
temp = Tempfile.new('server')
open('/etc/dnsmasq.d/server').each_line do |line|
temp.write(line.sub(/^# /, ''))
end
temp.flush
FileUtils.mv temp.path, '/etc/dnsmasq.d/server'

restart_dnsmasq
end

def offline!
FileUtils.touch(OFFLINE_FILE)
FileUtils.cp(OFFLINE_TEMPLATE, OFFLINE_CONF)

# Comment out upstream DNS servers in /etc/dnsmasq.d/server
# to prevent DNS loops.
temp = Tempfile.new('server')
open('/etc/dnsmasq.d/server').each_line do |line|
if line[/^# /]
new_line = line
else
new_line = "# #{line}"
end
temp.write new_line
end
temp.flush
FileUtils.mv temp.path, '/etc/dnsmasq.d/server'

restart_dnsmasq
end

Expand Down Expand Up @@ -246,7 +272,7 @@ def dns(dns_string)
servers = dns_string.split(/,/).map { |s| s.gsub(/\s+/, '') }
open('/etc/dnsmasq.d/server', 'w') do |f|
servers.each do |s|
f.puts("server=#{s}")
f.puts "#{offline? ? '# ' : ''}server=#{s}"
end
end
restart_dnsmasq
Expand Down

0 comments on commit b388031

Please sign in to comment.