ey_stonith 0.3.6 → 0.4.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/Gemfile +3 -0
- data/Rakefile +26 -0
- data/ey_stonith.gemspec +36 -0
- data/features/check.feature +57 -0
- data/features/cron.feature +67 -0
- data/features/fixtures/dead.ru +6 -0
- data/features/fixtures/healthy.ru +1 -0
- data/features/help.feature +7 -0
- data/features/not_found.feature +24 -0
- data/features/notify.feature +35 -0
- data/features/resume.feature +49 -0
- data/features/steps/stonith_steps.rb +40 -0
- data/features/stop.feature +48 -0
- data/features/support/env.rb +77 -0
- data/lib/ey_stonith/awsm_notifier.rb +13 -8
- data/lib/ey_stonith/commands/abstract.rb +0 -4
- data/lib/ey_stonith/commands/check.rb +13 -36
- data/lib/ey_stonith/commands/claim.rb +5 -96
- data/lib/ey_stonith/commands/cron.rb +3 -5
- data/lib/ey_stonith/commands/info.rb +1 -4
- data/lib/ey_stonith/commands/not_found.rb +1 -0
- data/lib/ey_stonith/commands/notify.rb +16 -55
- data/lib/ey_stonith/commands/reset.rb +0 -1
- data/lib/ey_stonith/commands/stop.rb +0 -1
- data/lib/ey_stonith/commands/takeover.rb +5 -90
- data/lib/ey_stonith/commands.rb +1 -1
- data/lib/ey_stonith/config.rb +17 -66
- data/lib/ey_stonith/rackapp.rb +26 -2
- data/lib/ey_stonith.rb +8 -15
- data/spec/config_spec.rb +53 -0
- data/spec/fixtures/config.yml +11 -0
- data/spec/fixtures/empty.yml +1 -0
- data/spec/helpers.rb +15 -0
- data/spec/history_spec.rb +58 -0
- data/spec/rackapp_spec.rb +100 -0
- data/spec/spec_helper.rb +24 -0
- metadata +240 -60
- data/lib/ey_stonith/address_stealer.rb +0 -40
- data/lib/ey_stonith/check_recorder.rb +0 -55
- data/lib/ey_stonith/data.rb +0 -11
- data/lib/ey_stonith/database.rb +0 -78
data/lib/ey_stonith/database.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'redis'
|
2
|
-
|
3
|
-
module EY
|
4
|
-
module Stonith
|
5
|
-
class Database
|
6
|
-
def initialize(config)
|
7
|
-
@config = config
|
8
|
-
end
|
9
|
-
|
10
|
-
def with_locked_data
|
11
|
-
raise "Already locked!" if @locked
|
12
|
-
@locked = true
|
13
|
-
data = locked_get
|
14
|
-
yield data
|
15
|
-
ensure
|
16
|
-
set(data) if @locked
|
17
|
-
end
|
18
|
-
|
19
|
-
def with_data
|
20
|
-
raise "Locked!" if @locked
|
21
|
-
data = get
|
22
|
-
yield data if data
|
23
|
-
end
|
24
|
-
|
25
|
-
def set(data)
|
26
|
-
unless get # very small race condition (very)
|
27
|
-
redis.lpush(master_key, Marshal.dump(data))
|
28
|
-
@locked = false
|
29
|
-
true
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def reset
|
34
|
-
redis.ltrim master_key, 1, 0
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def get
|
40
|
-
result = redis.lindex(master_key, 0) # index 0
|
41
|
-
result && Marshal.load(result)
|
42
|
-
end
|
43
|
-
|
44
|
-
# popping & locking
|
45
|
-
def locked_get
|
46
|
-
Marshal.load redis.blpop(master_key, @config.redis_timeout).last
|
47
|
-
end
|
48
|
-
|
49
|
-
def master_key
|
50
|
-
"#{@config.redis_key}:master"
|
51
|
-
end
|
52
|
-
|
53
|
-
def redis
|
54
|
-
@redis ||= load_redis
|
55
|
-
end
|
56
|
-
|
57
|
-
def load_redis
|
58
|
-
redis = Redis.new(:host => @config.redis_host, :port => @config.redis_port, :db => @config.redis_db, :timeout => @config.redis_timeout)
|
59
|
-
check_redis_version redis.info['redis_version']
|
60
|
-
redis
|
61
|
-
rescue Errno::ECONNREFUSED
|
62
|
-
abort "Unable to connect to redis"
|
63
|
-
end
|
64
|
-
|
65
|
-
def check_redis_version(version)
|
66
|
-
major, minor, patch = version.split('.').map { |num| num.to_i }
|
67
|
-
unless major > 1 ||
|
68
|
-
(major == 1 && minor > 3) ||
|
69
|
-
(major == 1 && minor == 3 && patch >= 1)
|
70
|
-
abort <<-ERROR
|
71
|
-
Redis server version [#{version}] is too old.
|
72
|
-
>= 1.3.1 required for blpop support.
|
73
|
-
ERROR
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|