Class: VagrantAutoDNS::Daemon
- Inherits:
-
RExec::Daemon::Base
- Object
- RExec::Daemon::Base
- VagrantAutoDNS::Daemon
- Defined in:
- lib/vagrant-autodns/daemon.rb
Constant Summary collapse
- ProcessFile =
RExec::Daemon::ProcessFile
- A_RECORD =
Resolv::DNS::Resource::IN::A
- AAAA_RECORD =
Resolv::DNS::Resource::IN::AAAA
- @@base_directory =
nil
Class Attribute Summary collapse
-
.db_file ⇒ Object
Returns the value of attribute db_file.
-
.enable_ipv6 ⇒ Object
Returns the value of attribute enable_ipv6.
-
.listen_ip ⇒ Object
Returns the value of attribute listen_ip.
-
.listen_port ⇒ Object
Returns the value of attribute listen_port.
-
.resolver ⇒ Object
Returns the value of attribute resolver.
-
.working_directory ⇒ Object
Returns the value of attribute working_directory.
Class Method Summary collapse
- .autodnsdb ⇒ Object
- .autodnsdb_path ⇒ Object
- .daemon_status ⇒ Object
- .ensure_running ⇒ Object
- .ipv6_enabled? ⇒ Boolean
- .pid ⇒ Object
- .restart ⇒ Object
- .run ⇒ Object
- .running? ⇒ Boolean
- .stopped? ⇒ Boolean
Class Attribute Details
.db_file ⇒ Object
Returns the value of attribute db_file.
28 29 30 |
# File 'lib/vagrant-autodns/daemon.rb', line 28 def db_file @db_file end |
.enable_ipv6 ⇒ Object
Returns the value of attribute enable_ipv6.
29 30 31 |
# File 'lib/vagrant-autodns/daemon.rb', line 29 def enable_ipv6 @enable_ipv6 end |
.listen_ip ⇒ Object
Returns the value of attribute listen_ip.
29 30 31 |
# File 'lib/vagrant-autodns/daemon.rb', line 29 def listen_ip @listen_ip end |
.listen_port ⇒ Object
Returns the value of attribute listen_port.
29 30 31 |
# File 'lib/vagrant-autodns/daemon.rb', line 29 def listen_port @listen_port end |
.resolver ⇒ Object
Returns the value of attribute resolver.
28 29 30 |
# File 'lib/vagrant-autodns/daemon.rb', line 28 def resolver @resolver end |
.working_directory ⇒ Object
Returns the value of attribute working_directory.
28 29 30 |
# File 'lib/vagrant-autodns/daemon.rb', line 28 def working_directory @working_directory end |
Class Method Details
.autodnsdb ⇒ Object
93 94 95 96 |
# File 'lib/vagrant-autodns/daemon.rb', line 93 def self.autodnsdb return @autodnsdb if @autodnsdb.is_a?(AutoDNSDB) @autodnsdb = AutoDNSDB.new(autodnsdb_path) end |
.autodnsdb_path ⇒ Object
98 99 100 |
# File 'lib/vagrant-autodns/daemon.rb', line 98 def self.autodnsdb_path @autodnsdb_path ||= File.(File.join(working_directory, db_file)) end |
.daemon_status ⇒ Object
73 74 75 |
# File 'lib/vagrant-autodns/daemon.rb', line 73 def self.daemon_status ProcessFile.status(self) end |
.ensure_running ⇒ Object
69 70 71 |
# File 'lib/vagrant-autodns/daemon.rb', line 69 def self.ensure_running restart unless running? end |
.ipv6_enabled? ⇒ Boolean
89 90 91 |
# File 'lib/vagrant-autodns/daemon.rb', line 89 def self.ipv6_enabled? @enable_ipv6.nil? || @enable_ipv6 end |
.pid ⇒ Object
77 78 79 |
# File 'lib/vagrant-autodns/daemon.rb', line 77 def self.pid ProcessFile.recall(self) end |
.restart ⇒ Object
64 65 66 67 |
# File 'lib/vagrant-autodns/daemon.rb', line 64 def self.restart stop unless stopped? start end |
.run ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vagrant-autodns/daemon.rb', line 32 def self.run upstream = upstream_resolver db_lib = AutoDNSDB db_absolute_path = autodnsdb_path allow_ipv6 = ipv6_enabled? RubyDNS::run_server(:listen => listen_interface) do db = db_lib.new(db_absolute_path) match(//, A_RECORD) do |transaction| domain = transaction.name.to_s.encode('US-ASCII') record = db.find_record(domain) if record transaction.respond!(record['ip']) else transaction.passthrough!(upstream) end end match(//, AAAA_RECORD) do |transaction| if allow_ipv6 transaction.passthrough!(upstream) else transaction.fail!(:NXDomain) end end # Default DNS handler otherwise do |transaction| transaction.passthrough!(upstream) end end end |
.running? ⇒ Boolean
81 82 83 |
# File 'lib/vagrant-autodns/daemon.rb', line 81 def self.running? daemon_status == :running end |
.stopped? ⇒ Boolean
85 86 87 |
# File 'lib/vagrant-autodns/daemon.rb', line 85 def self.stopped? daemon_status == :stopped end |