murakumo 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/murakumo-show-ip-address +2 -0
- data/etc/murakumo.server +9 -2
- data/etc/murakumo.yml.example +9 -2
- data/lib/cli/murakumo_initializer_context.rb +14 -0
- data/lib/cli/murakumo_options.rb +45 -37
- data/lib/misc/murakumo_const.rb +1 -1
- data/lib/srv/murakumo_balancer.rb +3 -4
- data/lib/srv/murakumo_cloud.rb +2 -2
- data/lib/srv/murakumo_health_checker.rb +1 -1
- metadata +10 -7
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
|
data/etc/murakumo.yml.example
CHANGED
@@ -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
|
data/lib/cli/murakumo_options.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
152
|
-
|
153
|
-
options[:aliases] =
|
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
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
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
|
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
|
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
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
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
|
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|
|
data/lib/misc/murakumo_const.rb
CHANGED
@@ -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)
|
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
|
-
|
126
|
-
|
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 }))
|
data/lib/srv/murakumo_cloud.rb
CHANGED
@@ -71,8 +71,8 @@ module Murakumo
|
|
71
71
|
# ヘルスチェック
|
72
72
|
@health_checkers = {}
|
73
73
|
|
74
|
-
if options
|
75
|
-
health_check = options
|
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:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
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-
|
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:
|
60
|
+
hash: 19
|
61
61
|
segments:
|
62
62
|
- 0
|
63
63
|
- 2
|
64
|
-
-
|
65
|
-
version: 0.2.
|
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
|