Class: VagrantPlugins::DNS::DNSServer
- Inherits:
-
Object
- Object
- VagrantPlugins::DNS::DNSServer
- Defined in:
- lib/vagrant-dns/dns_server.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ DNSServer
constructor
A new instance of DNSServer.
- #restart! ⇒ Object
- #run!(run_options) ⇒ Object
- #start! ⇒ Object
- #stop! ⇒ Object
Constructor Details
#initialize(options) ⇒ DNSServer
Returns a new instance of DNSServer.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/vagrant-dns/dns_server.rb', line 4 def initialize() @config = .fetch(:config) { raise "" } @dir = .fetch(:dir) { raise "" } @log_dir = .fetch(:dir, @dir) @run_options = { dir_mode: :normal, dir: @dir, log_output: true, log_dir: @log_dir, } end |
Instance Method Details
#restart! ⇒ Object
55 56 57 58 |
# File 'lib/vagrant-dns/dns_server.rb', line 55 def restart! stop! start! end |
#run!(run_options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vagrant-dns/dns_server.rb', line 25 def run!() require "daemons" Daemons.run_proc("vagrant-dns", ) do require 'rubydns' require 'rubydns/system' # Here the registry file has been created, so we can read it and # respond! registry = YAML.load(File.read(@config)) std_resolver = RubyDNS::Resolver.new(RubyDNS::System::nameservers) RubyDNS::run_server(listen: VagrantPlugins::DNS.listen) do registry.each do |pattern, ip| match(Regexp.new(pattern), Resolv::DNS::Resource::IN::A) \ do |transaction, match_data| transaction.respond!(ip) end end otherwise do |transaction| transaction.passthrough!(std_resolver) do |reply, reply_name| puts reply puts reply_name end end end end end |
#start! ⇒ Object
17 18 19 |
# File 'lib/vagrant-dns/dns_server.rb', line 17 def start! run! @run_options.merge ARGV: ["start"] end |
#stop! ⇒ Object
21 22 23 |
# File 'lib/vagrant-dns/dns_server.rb', line 21 def stop! run! @run_options.merge ARGV: ["stop"] end |