Class: VagrantDns::Server
- Inherits:
-
Object
- Object
- VagrantDns::Server
- Defined in:
- lib/vagrant_dns/server.rb
Instance Method Summary collapse
-
#initialize ⇒ Server
constructor
A new instance of Server.
- #process ⇒ Object
- #shutdown ⇒ Object
- #traps ⇒ Object
- #unpack(message) ⇒ Object
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
3 4 5 6 |
# File 'lib/vagrant_dns/server.rb', line 3 def initialize traps @resolv = VagrantDns::ResolvConf.new end |
Instance Method Details
#process ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vagrant_dns/server.rb', line 14 def process begin # @resolv.append zmq = EM::ZeroMQ::Context.new(1) EM.run { @dns = VagrantDns::DnsServer.new puts "processing " pull= zmq.socket(ZMQ::SUB) pull.bind(CONF.get('zmq_url')) pull.subscribe('vagrant') pull.on(:message) { |part| host, ip, stat= unpack(part.copy_out_string) puts "[#{ip}->#{host}]: is #{stat.to_s}" REG.register(host,ip) if :up.eql?(stat) REG.delete(host) if :down.eql?(stat) part.close } } rescue => e $stderr.puts e $stderr.puts e.backtrace.join("\n") shutdown end end |
#shutdown ⇒ Object
45 46 47 48 49 |
# File 'lib/vagrant_dns/server.rb', line 45 def shutdown $stderr.puts "Cleaning up server" # @resolv.clear EM::stop() end |
#traps ⇒ Object
39 40 41 42 43 |
# File 'lib/vagrant_dns/server.rb', line 39 def traps %w(INT SIGINT TERM).each{|s| Signal.trap(s) {shutdown} } end |
#unpack(message) ⇒ Object
9 10 11 12 |
# File 'lib/vagrant_dns/server.rb', line 9 def unpack() _, host, ip, msg = .split ' ', 4 [host, ip, msg.to_sym] end |