Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'rexec'
- require 'rexec/daemon'
- require 'rubydns'
- require 'timeout'
- RUN_AS="daemon"
- # Cache DNS entries for 5 minutes
- CACHE_TIME=60*5
- # We need to be root in order to bind to privileged port
- if RExec.current_user != "root"
- $stderr.puts "Sorry, this command needs to be run as root!"
- exit 1
- end
- # Helper
- Name = Resolv::DNS::Name
- Google = '8.8.8.8'
- Servers = {
- :php => '192.168.10.1',
- :ror => '192.168.10.2',
- :sql => '192.168.10.3',
- # ...
- }
- # The Daemon itself
- class Server < RExec::Daemon::Base
- @@var_directory = File.dirname(__FILE__)
- def self.run
- # Don't buffer output (for debug purposes)
- $stderr.sync = true
- # Use upstream DNS for name resolution
- $R = Resolv::DNS.new(:nameserver => Google)
- $CACHE = {}
- # Start the RubyDNS server
- RubyDNS::run_server do
- on(:start) do
- RExec.change_user(RUN_AS)
- end
- Servers.each do |name, addr|
- match(/(.+).#{name.to_s}.dev$/, :A) do |match, transaction|
- transaction.respond!(addr)
- end
- end
- # Default DNS handler
- otherwise do |transaction|
- transaction.passthrough!($R)
- end
- end
- end
- end
- # RExec daemon runner
- Server.daemonize
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement