murakumo 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- MRKM_DIR = 'murakumo-0.1.4'
3
2
  INIT_D_DIR = '/etc/init.d'
4
3
 
5
4
  begin
@@ -19,5 +18,5 @@ else
19
18
  exit 1
20
19
  end
21
20
 
22
- `cp -i #{gem_dir}/#{MRKM_DIR}/etc/murakumo.server #{INIT_D_DIR}/murakumo`
21
+ `cp -i #{gem_dir}/murakumo-*/etc/murakumo.server #{INIT_D_DIR}/murakumo`
23
22
  `chmod 755 #{INIT_D_DIR}/murakumo`
data/etc/murakumo.server CHANGED
@@ -91,10 +91,23 @@ host: $ip_addr, $hostname, 60
91
91
  # http_get '/index.html'
92
92
  EOF
93
93
 
94
+ chmod 600 $conf
95
+
94
96
  echo "configuration file was created: $conf"
95
97
  echo -e "\033[0;31mPlease set 127.0.0.1 to resolv.conf.\033[0;39m"
96
98
  ;;
99
+ hup)
100
+ PID=`ps -ef | awk '/ruby/ && /murakumo/ && !/awk/{print $2}'`
101
+
102
+ if [ -n "$PID" ]; then
103
+ echo "sent HUP to murakumo($PID)."
104
+ kill -HUP $PID
105
+ else
106
+ echo 'pid is not found.'
107
+ exit 1
108
+ fi
109
+ ;;
97
110
  *)
98
- echo $"Usage: $0 {start|stop|restart|status|save|configureh}"
111
+ echo $"Usage: $0 {start|stop|restart|status|save|configure|hup}"
99
112
  exit 1
100
113
  esac
data/lib/cli/mrkmctl.rb CHANGED
@@ -17,17 +17,10 @@ begin
17
17
  case cmd
18
18
  # 一覧表示
19
19
  when :list
20
- records = if arg.kind_of?(String)
21
- # 引数がある場合はフィルタリング
22
- there.list_records.select {|r| r[0..1].any?{|i| i.start_with?(arg) } }
23
- else
24
- there.list_records
25
- end
20
+ # レコードの取得
21
+ records = there.list_records
26
22
 
27
- puts <<-EOF
28
- IP address TTL Priority Activity Hostname
29
- --------------- ------ --------- -------- ----------
30
- EOF
23
+ # 値の書き換え
31
24
  records.each do |r|
32
25
  priority = case r[3]
33
26
  when Murakumo::ORIGIN
@@ -42,6 +35,18 @@ IP address TTL Priority Activity Hostname
42
35
 
43
36
  r[3] = priority
44
37
  r[4] = (r[4] == Murakumo::ACTIVE ? 'Active' : 'Inactive')
38
+ end
39
+
40
+ if arg.kind_of?(String)
41
+ # 引数がある場合はフィルタリング(TTLを除く)
42
+ records = records.select {|r| r.values_at(0, 1, 3, 4).any?{|i| i.to_s =~ /\A#{arg.to_s}/i } }
43
+ end
44
+
45
+ puts <<-EOF
46
+ IP address TTL Priority Activity Hostname
47
+ --------------- ------ --------- -------- ----------
48
+ EOF
49
+ records.each do |r|
45
50
  puts '%-15s %6d %-9s %-8s %s' % r.values_at(0, 2, 3, 4, 1)
46
51
  end
47
52
 
@@ -10,7 +10,7 @@ Version = Murakumo::VERSION
10
10
  def murakumo_parse_args
11
11
  optopus do
12
12
  desc 'key for authentication (required)'
13
- option :auth_key, '-K', '--auth-key STRING', :required => true
13
+ option :auth_key, '-K', '--auth-key STRING_OR_PATH', :required => true
14
14
 
15
15
  desc 'ip address to bind'
16
16
  option :dns_address, '-a', '--address IP', :default => '0.0.0.0' do |value|
@@ -114,6 +114,11 @@ def murakumo_parse_args
114
114
  option :gossip_receive_timeout, '-O', '--gossip-receive-timeout NUM', :type => Integer, :default => 3
115
115
 
116
116
  after do |options|
117
+ # auth_key
118
+ if File.exist?(options[:auth_key])
119
+ options[:auth_key] = File.read(options[:auth_key]).strip
120
+ end
121
+
117
122
  # resolver
118
123
  if options[:resolver]
119
124
  options[:resolver] = options[:resolver].map {|i| i.strip }
@@ -168,6 +173,13 @@ def murakumo_parse_args
168
173
 
169
174
  options[:logger] = Logger.new(options[:log_path] || $stderr)
170
175
  options[:logger].level = Logger.const_get(options[:log_level].to_s.upcase)
176
+
177
+ # check same hostname
178
+ hostnames = [options[:host][0].downcase] + options[:aliases].map {|i| i[0].downcase }
179
+
180
+ if hostnames.length != hostnames.uniq.length
181
+ raise OptionParser::ParseError, 'same hostname was found'
182
+ end
171
183
  end
172
184
 
173
185
  error do |e|
@@ -1,5 +1,5 @@
1
1
  module Murakumo
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
 
4
4
  # Priority
5
5
  MASTER = 1
@@ -13,6 +13,7 @@ module Murakumo
13
13
  attr_reader :address
14
14
  attr_reader :gossip
15
15
  attr_reader :db
16
+ attr_reader :hostname
16
17
 
17
18
  def initialize(options)
18
19
  # オプションはインスタンス変数に保存
@@ -21,8 +22,10 @@ module Murakumo
21
22
  # リソースレコードからホストのアドレスとデータを取り出す
22
23
  host_data = options[:host]
23
24
  @address = host_data.shift
25
+ @hostname = host_data.first
24
26
  host_data.concat [ORIGIN, ACTIVE]
25
27
  alias_datas = options[:aliases].map {|r| r + [ACTIVE] }
28
+ @logger = options[:logger]
26
29
 
27
30
  # 名前は小文字に変換
28
31
  datas = ([host_data] + alias_datas).map do |i|
@@ -45,7 +48,7 @@ module Murakumo
45
48
  :node_lifetime => options[:gossip_node_lifetime],
46
49
  :gossip_interval => options[:gossip_send_interval],
47
50
  :receive_timeout => options[:gossip_receive_timeout],
48
- :logger => options[:logger],
51
+ :logger => @logger,
49
52
  })
50
53
 
51
54
  # ノードの更新をフック
@@ -70,12 +73,19 @@ module Murakumo
70
73
 
71
74
  if health_check.kind_of?(Hash)
72
75
  health_check.each do |name, conf|
73
- checker = HealthChecker.new(name.downcase, self, options[:logger], conf)
74
- @health_checkers[name] = checker
75
- # ヘルスチェックはまだ起動しない
76
+ name = name.downcase
77
+
78
+ if datas.any? {|i| i[0] == name }
79
+ checker = HealthChecker.new(name, self, @logger, conf)
80
+ @health_checkers[name] = checker
81
+ # ヘルスチェックはまだ起動しない
82
+ else
83
+ # ホスト名になかったら警告
84
+ @logger.warn("host for a health check is not found: #{name}")
85
+ end
76
86
  end
77
87
  else
78
- options[:logger].warn('configuration of a health check is not right')
88
+ @logger.warn('configuration of a health check is not right')
79
89
  end
80
90
  end
81
91
  end
@@ -308,6 +318,11 @@ module Murakumo
308
318
  # 名前は小文字に変換
309
319
  name = name.downcase
310
320
 
321
+ # ホスト名と同じなら警告
322
+ if name == @hostname
323
+ @logger.warn('same hostname as origin was found')
324
+ end
325
+
311
326
  @db.execute(<<-EOS, address, name, ttl, priority, activity)
312
327
  REPLACE INTO records (ip_address, name, ttl, priority, activity)
313
328
  VALUES (?, ?, ?, ?, ?)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: murakumo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - winebarrel
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-19 00:00:00 Z
18
+ date: 2011-11-20 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rubydns