Class: VagrantDNS::Service
- Inherits:
-
Object
- Object
- VagrantDNS::Service
- Defined in:
- lib/vagrant-dns/service.rb
Instance Attribute Summary collapse
-
#tmp_path ⇒ Object
Returns the value of attribute tmp_path.
Instance Method Summary collapse
- #config_file ⇒ Object
-
#initialize(tmp_path) ⇒ Service
constructor
A new instance of Service.
- #restart!(start_opts = {}) ⇒ Object
- #run!(run_options) ⇒ Object
- #runopts ⇒ Object
- #start!(opts = {}) ⇒ Object
- #stop! ⇒ Object
Constructor Details
#initialize(tmp_path) ⇒ Service
Returns a new instance of Service.
8 9 10 |
# File 'lib/vagrant-dns/service.rb', line 8 def initialize(tmp_path) self.tmp_path = tmp_path end |
Instance Attribute Details
#tmp_path ⇒ Object
Returns the value of attribute tmp_path.
6 7 8 |
# File 'lib/vagrant-dns/service.rb', line 6 def tmp_path @tmp_path end |
Instance Method Details
#config_file ⇒ Object
65 66 67 |
# File 'lib/vagrant-dns/service.rb', line 65 def config_file File.join(tmp_path, "config") end |
#restart!(start_opts = {}) ⇒ Object
50 51 52 53 |
# File 'lib/vagrant-dns/service.rb', line 50 def restart!(start_opts = {}) stop! start!(start_opts) 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 |
# File 'lib/vagrant-dns/service.rb', line 25 def run!() Daemons.run_proc("vagrant-dns", ) do require 'rubydns' require 'rubydns/system' registry = YAML.load(File.read(config_file)) std_resolver = RubyDNS::Resolver.new(RubyDNS::System::nameservers) RubyDNS::run_server(:listen => VagrantDNS::Config.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 |
#runopts ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/vagrant-dns/service.rb', line 55 def runopts daemon_dir = File.join(tmp_path, "daemon") { :dir_mode => :normal, :dir => daemon_dir, :log_output => true, :log_dir => daemon_dir } end |
#start!(opts = {}) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/vagrant-dns/service.rb', line 12 def start!(opts = {}) = { :ARGV => ["start"], :ontop => opts[:ontop] }.merge!(runopts) run!() end |
#stop! ⇒ Object
20 21 22 23 |
# File 'lib/vagrant-dns/service.rb', line 20 def stop! = {:ARGV => ["stop"]}.merge(runopts) run!() end |