Class: VagrantDNS::Service
- Inherits:
-
Object
- Object
- VagrantDNS::Service
- Defined in:
- lib/vagrant-dns/service.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#tmp_path ⇒ Object
Returns the value of attribute tmp_path.
Instance Method Summary collapse
- #config_file ⇒ Object
-
#initialize(tmp_path, options = {}) ⇒ Service
constructor
A new instance of Service.
- #restart! ⇒ Object
- #run!(run_options) ⇒ Object
- #runopts ⇒ Object
- #start! ⇒ Object
- #stop! ⇒ Object
Constructor Details
#initialize(tmp_path, options = {}) ⇒ Service
Returns a new instance of Service.
5 6 7 8 |
# File 'lib/vagrant-dns/service.rb', line 5 def initialize(tmp_path, = {}) self.tmp_path = tmp_path self. = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/vagrant-dns/service.rb', line 3 def @options end |
#tmp_path ⇒ Object
Returns the value of attribute tmp_path.
3 4 5 |
# File 'lib/vagrant-dns/service.rb', line 3 def tmp_path @tmp_path end |
Instance Method Details
#config_file ⇒ Object
68 69 70 |
# File 'lib/vagrant-dns/service.rb', line 68 def config_file File.join(tmp_path, "config") end |
#restart! ⇒ Object
56 57 58 59 |
# File 'lib/vagrant-dns/service.rb', line 56 def restart! stop! start! end |
#run!(run_options) ⇒ Object
20 21 22 23 24 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 54 |
# File 'lib/vagrant-dns/service.rb', line 20 def run!() Daemons.run_proc("vagrant-dns", ) do require 'resolv' require 'rubydns' # come on, this is Ruby # Ruby 1.9.3 does not implement :make_requester anymore # Luckily :make_udp_requester is just the same begin Resolv::DNS.instance_method(:make_requester) rescue NameError Resolv::DNS.class_eval { alias :make_requester :make_udp_requester } end registry = YAML.load(File.read(config_file)) std_resolver = Resolv::DNS.new RubyDNS::run_server(:listen => VagrantDNS::Config.listen) do registry.each do |pattern, ip| match(Regexp.new(pattern), :A) do |match_data, transaction| 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 |
#runopts ⇒ Object
61 62 63 64 65 66 |
# File 'lib/vagrant-dns/service.rb', line 61 def runopts {:dir_mode => :normal, :dir => File.join(tmp_path, "daemon"), :log_output => true, :log_dir => File.join(tmp_path, "daemon")} end |
#start! ⇒ Object
10 11 12 13 |
# File 'lib/vagrant-dns/service.rb', line 10 def start! = {:ARGV => ["start"]}.merge().merge(runopts) run!() end |
#stop! ⇒ Object
15 16 17 18 |
# File 'lib/vagrant-dns/service.rb', line 15 def stop! = {:ARGV => ["stop"]}.merge().merge(runopts) run!() end |