murakumo 0.3.8 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ puts `/sbin/ifconfig eth0 | awk -F'[: ]+' '/^eth0/,/^$/{if(/inet addr/) print $4}'`.strip
data/etc/murakumo.server CHANGED
@@ -72,6 +72,13 @@ max-ip-num: 8
72
72
  #domain: ap-northeast-1.compute.internal
73
73
  #enable-cache: true
74
74
 
75
+ # specify the script which initializes a setup
76
+ #init-script: |
77
+ # @options['initial-nodes'] = '10.11.12.20, 10.11.12.21'
78
+
79
+ # (another way)
80
+ #init-script: /foo/bar/zoo/murakumo-init.rb
81
+
75
82
  #name-includes: ^app-\d+$, ^db-\d+$
76
83
  #name-excludes:
77
84
  #addr-includes: ^10\..*
@@ -83,11 +90,11 @@ max-ip-num: 8
83
90
  # max-ip-num: 1
84
91
  # ^db-.*: # destination alias regex
85
92
  # algorithm: fix_by_src # balancing algorithm
86
- # sources: foo, bar # source alias name
93
+ # sources: foo, bar # source alias name (fix_by_src only)
87
94
  # max-ip-num: 8
88
95
  # ^cache-.*: # destination alias regex
89
96
  # algorithm: fix_by_src2 # balancing algorithm
90
- # sources: zoo # source alias name
97
+ # sources: zoo # source alias name (fix_by_src only)
91
98
 
92
99
  #notification:
93
100
  # host: my.smtp.server
@@ -12,6 +12,13 @@ max-ip-num: 8
12
12
  #domain: ap-northeast-1.compute.internal
13
13
  #enable-cache: true
14
14
 
15
+ # specify the script which initializes a setup
16
+ #init-script: |
17
+ # @options['initial-nodes'] = '10.11.12.20, 10.11.12.21'
18
+
19
+ # (another way)
20
+ #init-script: /foo/bar/zoo/murakumo-init.rb
21
+
15
22
  #name-includes: ^app-\d+$, ^db-\d+$
16
23
  #name-excludes:
17
24
  #addr-includes: ^10\..*
@@ -23,11 +30,11 @@ max-ip-num: 8
23
30
  # max-ip-num: 1
24
31
  # ^db-.*: # destination alias regex
25
32
  # algorithm: fix_by_src # balancing algorithm
26
- # sources: foo, bar # source alias name
33
+ # sources: foo, bar # source alias name (fix_by_src only)
27
34
  # max-ip-num: 8
28
35
  # ^cache-.*: # destination alias regex
29
36
  # algorithm: fix_by_src2 # balancing algorithm
30
- # sources: zoo # source alias name
37
+ # sources: zoo # source alias name (fix_by_src only)
31
38
 
32
39
  #notification:
33
40
  # host: my.smtp.server
@@ -0,0 +1,14 @@
1
+ require 'misc/murakumo_const'
2
+
3
+ module Murakumo
4
+
5
+ # 設定初期化スクリプトのコンテキスト
6
+ class InitializerContext
7
+
8
+ def initialize(options)
9
+ @options = options
10
+ end
11
+
12
+ end # InitializerContext
13
+
14
+ end # Murakumo
@@ -3,6 +3,7 @@ require 'optopus'
3
3
  require 'resolv'
4
4
  require 'socket'
5
5
 
6
+ require 'cli/murakumo_initializer_context'
6
7
  require 'misc/murakumo_const'
7
8
 
8
9
  unless defined?(Version)
@@ -11,6 +12,13 @@ end
11
12
 
12
13
  def murakumo_parse_args
13
14
  optopus do
15
+ before do |options|
16
+ if (script = options['init-script'])
17
+ script = File.read(script) if File.exists?(script)
18
+ Murakumo::InitializerContext.new(options).instance_eval(script)
19
+ end
20
+ end
21
+
14
22
  desc 'key for authentication (required)'
15
23
  option :auth_key, '-K', '--auth-key STRING_OR_PATH', :required => true
16
24
 
@@ -146,36 +154,37 @@ def murakumo_parse_args
146
154
  options[:host][2] = (options[:host][2] || 60).to_i # TTL
147
155
 
148
156
  # aliases
149
- config_file_aliases = options.config_file ? options.config_file['alias'] : nil
157
+ if options[:aliases]
158
+ unless options[:aliases].kind_of?(Array)
159
+ parse_error('configuration of a aliases is not right')
160
+ end
150
161
 
151
- if config_file_aliases
152
- if config_file_aliases.kind_of?(Array)
153
- options[:aliases] = config_file_aliases.map {|i| i.split(',') }
154
- else
155
- options[:aliases] = [options[:aliases]]
162
+ # 設定ファイルからの設定の場合は「配列の配列」に変換
163
+ if options[:aliases][0].kind_of?(String)
164
+ options[:aliases] = options[:aliases].map {|i| i.split(',') }
156
165
  end
157
- end
158
166
 
159
- options[:aliases] = (options[:aliases] || []).map do |r|
160
- r = r.map {|i| i.to_s.strip }
161
- [nil, 60, 'master', 100].each_with_index {|v, i| r[i] ||= v }
162
-
163
- priority = case r[2].to_s
164
- when /master/i
165
- Murakumo::MASTER
166
- when /secondary/i
167
- Murakumo::SECONDARY
168
- else
169
- Murakumo::BACKUP
170
- end
171
-
172
- [
173
- r[0], # name
174
- r[1].to_i, # TTL
175
- priority,
176
- r[3].to_i, # weight
177
- ]
178
- end
167
+ options[:aliases] = (options[:aliases] || []).map do |r|
168
+ r = r.map {|i| i.to_s.strip }
169
+ [nil, 60, 'master', 100].each_with_index {|v, i| r[i] ||= v }
170
+
171
+ priority = case r[2].to_s
172
+ when /master/i
173
+ Murakumo::MASTER
174
+ when /secondary/i
175
+ Murakumo::SECONDARY
176
+ else
177
+ Murakumo::BACKUP
178
+ end
179
+
180
+ [
181
+ r[0], # name
182
+ r[1].to_i, # TTL
183
+ priority,
184
+ r[3].to_i, # weight
185
+ ]
186
+ end
187
+ end # aliases
179
188
 
180
189
  # logger
181
190
  if not options[:log_path] and options[:daemon]
@@ -193,7 +202,7 @@ def murakumo_parse_args
193
202
  end
194
203
 
195
204
  # health check
196
- if options.config_file and (health_check = options.config_file['health-check'])
205
+ if (health_check = options[:health_check])
197
206
  health_check.kind_of?(Hash) or parse_error('configuration of a health check is not right')
198
207
 
199
208
  health_check.each do |name, conf|
@@ -213,7 +222,7 @@ def murakumo_parse_args
213
222
  end # health check
214
223
 
215
224
  # notification
216
- if options.config_file and (ntfc = options.config_file['notification'])
225
+ if (ntfc = options[:notification])
217
226
  ntfc.kind_of?(Hash) or parse_error('configuration of a notification is not right')
218
227
 
219
228
  if (ntfc['host'] || '').empty?
@@ -250,17 +259,17 @@ def murakumo_parse_args
250
259
  end # notification
251
260
 
252
261
  # {name,addr}-{includes,excludes}
253
- if options.config_file
254
- %w(name-includes name-excludes addr-includes addr-excludes).each do |key|
255
- unless (reg_vals = (options.config_file[key] || '').strip).empty?
256
- reg_vals = reg_vals.split(/\s*,\s*/).select {|i| not i.empty? }.map {|i| Regexp.new(i.strip, Regexp::IGNORECASE) }
257
- options[key.gsub('-', '_').to_sym] = reg_vals
258
- end
262
+ [:name_includes, :name_excludes, :addr_includes, :addr_excludes].each do |key|
263
+ unless (reg_vals = (options[key] || '').strip).empty?
264
+ reg_vals = reg_vals.split(/\s*,\s*/).select {|i| not i.empty? }.map {|i| Regexp.new(i.strip, Regexp::IGNORECASE) }
265
+ options[key] = reg_vals
266
+ else
267
+ options.delete(key)
259
268
  end
260
269
  end # {name,addr}-{includes,excludes}
261
270
 
262
271
  # balancing
263
- if options.config_file and (balancing = options.config_file['balancing'])
272
+ if (balancing = options[:balancing])
264
273
  balancing.kind_of?(Hash) or parse_error('configuration of a balancing is not right')
265
274
  balancing_h = options[:balancing] = {}
266
275
 
@@ -307,7 +316,6 @@ def murakumo_parse_args
307
316
  balancing_h[reg_dest] = attrs_h
308
317
  end
309
318
  end # balancing
310
-
311
319
  end # after
312
320
 
313
321
  error do |e|
@@ -1,5 +1,5 @@
1
1
  module Murakumo
2
- VERSION = '0.3.8'
2
+ VERSION = '0.3.9'
3
3
 
4
4
  # Priority
5
5
  MASTER = 1
@@ -81,7 +81,7 @@ module Murakumo
81
81
  fix_by_src0(records, max_ip_num, src_aliases) do |new_records|
82
82
  # 先頭 + ランダムを返す
83
83
  first = new_records.shift
84
- [first] + new_records.slice(0, max_ip_num - 1).sort_by { rand }
84
+ [first] + new_records.sort_by { rand }.slice(0, max_ip_num - 1)
85
85
  end
86
86
  end
87
87
 
@@ -122,9 +122,8 @@ module Murakumo
122
122
  # 先頭を決めてローテート
123
123
  first_index = sources.zip(dests).index {|s, d| s == @address }
124
124
 
125
- unless first_index.zero?
126
- dests = (dests_orig + dests_orig).slice(first_index, dests.length)
127
- end
125
+ # 元の配列に戻す
126
+ dests = (dests_orig + dests_orig).slice(first_index, dests_orig.length)
128
127
 
129
128
  # 先頭インデックスからレコードを並べ直す
130
129
  yield(records.values_at(*dests.map {|addr, i| i }))
@@ -71,8 +71,8 @@ module Murakumo
71
71
  # ヘルスチェック
72
72
  @health_checkers = {}
73
73
 
74
- if options.config_file and options.config_file['health-check']
75
- health_check = options.config_file['health-check']
74
+ if options[:health_check]
75
+ health_check = options[:health_check]
76
76
 
77
77
  if health_check.kind_of?(Hash)
78
78
  health_check.each do |name, conf|
@@ -34,7 +34,7 @@ module Murakumo
34
34
  # スクリプトの読み込み
35
35
  @script = options['script']
36
36
  raise "health check script of #{@name} is not found" unless @script
37
- @script = File.read(script) if File.exists?(@script)
37
+ @script = File.read(@script) if File.exists?(@script)
38
38
 
39
39
  # 通知オブジェクトの設定
40
40
  if options[:notification]
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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 8
10
- version: 0.3.8
9
+ - 9
10
+ version: 0.3.9
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-12-10 00:00:00 Z
18
+ date: 2011-12-30 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rubydns
@@ -57,12 +57,12 @@ dependencies:
57
57
  requirements:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- hash: 21
60
+ hash: 19
61
61
  segments:
62
62
  - 0
63
63
  - 2
64
- - 1
65
- version: 0.2.1
64
+ - 2
65
+ version: 0.2.2
66
66
  type: :runtime
67
67
  version_requirements: *id003
68
68
  - !ruby/object:Gem::Dependency
@@ -87,6 +87,7 @@ executables:
87
87
  - murakumo
88
88
  - mrkmctl
89
89
  - murakumo-install-init-script
90
+ - murakumo-show-ip-address
90
91
  extensions: []
91
92
 
92
93
  extra_rdoc_files: []
@@ -94,12 +95,14 @@ extra_rdoc_files: []
94
95
  files:
95
96
  - README
96
97
  - bin/murakumo-install-init-script
98
+ - bin/murakumo-show-ip-address
97
99
  - bin/mrkmctl
98
100
  - bin/murakumo
99
101
  - lib/cli/murakumo_options.rb
100
102
  - lib/cli/mrkmctl.rb
101
103
  - lib/cli/mrkmctl_options.rb
102
104
  - lib/cli/murakumo.rb
105
+ - lib/cli/murakumo_initializer_context.rb
103
106
  - lib/srv/murakumo_health_check_notifier.rb
104
107
  - lib/srv/murakumo_balancer.rb
105
108
  - lib/srv/murakumo_server.rb