Class: Murakumo::Server

Inherits:
RExec::Daemon::Base
  • Object
show all
Defined in:
lib/srv/murakumo_server.rb

Overview

RExecに依存しているのでこんな設計に…

Class Method Summary collapse

Class Method Details

.init(options) ⇒ Object



20
21
22
23
24
# File 'lib/srv/murakumo_server.rb', line 20

def init(options)
  # クラスインスタンス変数を使わないこと
  @@options = options
  @@cloud = Cloud.new(options)
end

.pid_directory=(path) ⇒ Object



26
27
28
# File 'lib/srv/murakumo_server.rb', line 26

def pid_directory=(path)
  @@pid_directory = path
end

.runObject



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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/srv/murakumo_server.rb', line 30

def run
  RubyDNS.run_server(:listen => [[:udp, @@options[:dns_address], @@options[:dns_port]]]) do
    # RubyDNS::Serverのコンテキスト
    @logger = @@options[:logger] if @@options[:logger]

    on(:start) do
      if @@options[:socket]
        # ServerクラスをDRuby化
        DRb.start_service("drbunix:#{@@options[:socket]}", @@cloud)
        at_exit { FileUtils.rm_f(@@options[:socket]) }
      end

      # HUPでログをローテート
      if @@options[:logger]
        trap(:HUP) do
          if logger = @@options[:logger]
            logdev = logger.instance_variable_get(:@logdev)

            if (dev = logdev.dev).kind_of?(File)
              path = dev.path
              mutex = logdev.instance_variable_get(:@mutex)

              mutex.synchronize do
                dev.reopen(path, 'a')
                dev.sync = true
              end
            end
          end
        end
      end

      # ゴシッププロトコルを開始
      @@cloud.start
    end

    # look up A record
    match(@@cloud.method(:address_exist?), :A) do |transaction|
      records = @@cloud.lookup_addresses(transaction.name)

      records.each do |r|
        address, ttl = r
        transaction.respond!(address, :ttl => ttl)
      end
    end # match

    # look up PTR record
    match(@@cloud.method(:name_exist?), :PTR) do |transaction|
      name, ttl = @@cloud.lookup_name(transaction.name)
      transaction.respond!(Resolv::DNS::Name.create("#{name}."), :ttl => ttl)
    end

    if @@options[:resolver]
      otherwise do |transaction|
        transaction.passthrough!(@@options[:resolver])
      end
    end
  end # RubyDNS.run_server
end

.shutdownObject

run



89
90
91
# File 'lib/srv/murakumo_server.rb', line 89

def shutdown
  @@cloud.stop
end