Class: VagrantRubydns::Server

Inherits:
RExec::Daemon::Base
  • Object
show all
Defined in:
lib/vagrant-rubydns/server.rb

Constant Summary collapse

Name =
Resolv::DNS::Name
IN =
Resolv::DNS::Resource::IN

Class Method Summary collapse

Class Method Details

.interfacesObject



20
21
22
23
24
25
# File 'lib/vagrant-rubydns/server.rb', line 20

def self.interfaces
  [
    [:udp, "0.0.0.0", port],
    [:tcp, "0.0.0.0", port]
  ]
end

.pidObject



31
32
33
# File 'lib/vagrant-rubydns/server.rb', line 31

def self.pid
  RExec::Daemon::ProcessFile.recall(self)
end

.portObject



8
9
10
# File 'lib/vagrant-rubydns/server.rb', line 8

def self.port
  @port ||= 10053
end

.port=(port) ⇒ Object



12
13
14
# File 'lib/vagrant-rubydns/server.rb', line 12

def self.port=(port)
  @port = port
end

.preforkObject



44
45
46
47
# File 'lib/vagrant-rubydns/server.rb', line 44

def self.prefork
  super
  ResolverConfig.ensure_config_exists
end

.runObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vagrant-rubydns/server.rb', line 49

def self.run
  server = self
  RubyDNS::run_server(:listen => interfaces) do
    self.logger.level = Logger::INFO
    
    match(/.*/, IN::A) do |transaction|
      ip = Store.hosts.get(transaction.name)
      if ip
        transaction.respond!(ip)
      else
        transaction.passthrough!(server.upstream)
      end
    end

    # Default DNS handler
    otherwise do |transaction|
      transaction.passthrough!(server.upstream)
    end
  end
end

.running?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/vagrant-rubydns/server.rb', line 40

def self.running?
  RExec::Daemon::ProcessFile.status(self) == :running
end

.upstreamObject



27
28
29
# File 'lib/vagrant-rubydns/server.rb', line 27

def self.upstream
  @upstream ||= RubyDNS::Resolver.new(upstream_servers)
end

.upstream_serversObject



16
17
18
# File 'lib/vagrant-rubydns/server.rb', line 16

def self.upstream_servers
  [[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]]
end

.working_directoryObject

For RExec



36
37
38
# File 'lib/vagrant-rubydns/server.rb', line 36

def self.working_directory
  VagrantRubydns.working_dir
end