ey_stonith 0.2.1 → 0.3.0
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.
- data/lib/ey_stonith/awsm_notifier.rb +7 -9
- data/lib/ey_stonith/commands/check.rb +5 -1
- data/lib/ey_stonith/commands/notify.rb +4 -4
- data/lib/ey_stonith/config.rb +13 -3
- data/lib/ey_stonith/rackapp.rb +30 -0
- data/lib/ey_stonith.rb +25 -1
- metadata +19 -4
@@ -6,8 +6,8 @@ require 'timeout'
|
|
6
6
|
module EY
|
7
7
|
module Stonith
|
8
8
|
class AwsmNotifier
|
9
|
-
def initialize(instance_id, uri,
|
10
|
-
@instance_id, @uri, @
|
9
|
+
def initialize(instance_id, uri, token)
|
10
|
+
@instance_id, @uri, @token = instance_id, uri, token
|
11
11
|
end
|
12
12
|
|
13
13
|
def notify(success, unreachable, refused)
|
@@ -17,11 +17,9 @@ module EY
|
|
17
17
|
|
18
18
|
case code
|
19
19
|
when 200...300
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
refused.call body
|
24
|
-
end
|
20
|
+
success.call
|
21
|
+
when 410
|
22
|
+
refused.call body
|
25
23
|
else
|
26
24
|
unreachable.call
|
27
25
|
end
|
@@ -45,10 +43,10 @@ module EY
|
|
45
43
|
end
|
46
44
|
|
47
45
|
def payload
|
48
|
-
@
|
46
|
+
{'label' => @instance_id, 'token' => @token}
|
49
47
|
end
|
50
48
|
|
51
|
-
# ripped from restclient
|
49
|
+
# ripped from restclient
|
52
50
|
def process_payload(payload = nil, parent_key = nil)
|
53
51
|
payload.keys.map do |k|
|
54
52
|
key = parent_key ? "#{parent_key}[#{k}]" : k
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
1
3
|
module EY
|
2
4
|
module Stonith
|
3
5
|
module Commands
|
@@ -18,7 +20,9 @@ module EY
|
|
18
20
|
history << :check
|
19
21
|
|
20
22
|
begin
|
21
|
-
|
23
|
+
timeout(config.monitor_timeout) do
|
24
|
+
open("http://#{data.hostname}#{config.monitor_path}").read
|
25
|
+
end
|
22
26
|
rescue
|
23
27
|
bad_check(data.key, data.instance_id)
|
24
28
|
else
|
@@ -20,7 +20,7 @@ module EY
|
|
20
20
|
notify_path.delete if notify_path.exist?
|
21
21
|
|
22
22
|
database.with_data do |data|
|
23
|
-
abort_if_master
|
23
|
+
abort_if_master data.hostname
|
24
24
|
notify!
|
25
25
|
end
|
26
26
|
|
@@ -50,8 +50,8 @@ If you want to (destructively) notify AWSM that this instance is master, call wi
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def notify!
|
53
|
-
notifier = AwsmNotifier.new
|
54
|
-
notifier.notify
|
53
|
+
notifier = AwsmNotifier.new config.meta_data_id, config.takeover_uri, config.endpoint_token
|
54
|
+
notifier.notify method(:success), method(:unreachable), method(:refused)
|
55
55
|
end
|
56
56
|
|
57
57
|
def success
|
@@ -74,7 +74,7 @@ If you want to (destructively) notify AWSM that this instance is master, call wi
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def parser
|
77
|
-
super.on
|
77
|
+
super.on '-f', '--force', "Force the command (only applicable to claim currently)" do |f|
|
78
78
|
@force = f
|
79
79
|
end
|
80
80
|
super
|
data/lib/ey_stonith/config.rb
CHANGED
@@ -27,10 +27,12 @@ module EY
|
|
27
27
|
'log' => '/var/log/stonith.log',
|
28
28
|
'state_dir' => '/var/run/stonith',
|
29
29
|
'heartbeat' => 10,
|
30
|
-
'
|
30
|
+
'endpoint_uri' => nil,
|
31
|
+
'endpoint_token' => nil,
|
31
32
|
|
32
33
|
'monitor_host' => nil,
|
33
34
|
'monitor_path' => '/haproxy/monitor',
|
35
|
+
'monitor_timeout' => 5,
|
34
36
|
|
35
37
|
'redis_host' => nil,
|
36
38
|
'redis_port' => 6379,
|
@@ -69,7 +71,9 @@ Config:
|
|
69
71
|
history_path: #{history_path}
|
70
72
|
takeover_path: #{takeover_path}
|
71
73
|
|
72
|
-
|
74
|
+
endpoint_uri: #{endpoint_uri}
|
75
|
+
endpoint_token: #{endpoint_token}
|
76
|
+
takeover_uri: #{takeover_uri}
|
73
77
|
fog_credentials: #{fog_credentials.inspect}
|
74
78
|
awsm_credentials: #{awsm_credentials.inspect}
|
75
79
|
|
@@ -79,6 +83,7 @@ Config:
|
|
79
83
|
|
80
84
|
monitor_host: #{monitor_host}
|
81
85
|
monitor_path: #{monitor_path}
|
86
|
+
monitor_timeout: #{monitor_timeout}
|
82
87
|
|
83
88
|
redis_host: #{redis_host}
|
84
89
|
redis_port: #{redis_port}
|
@@ -96,7 +101,12 @@ Config:
|
|
96
101
|
def notify_path() state_path + 'notify' end
|
97
102
|
def history_path() state_path + 'history' end
|
98
103
|
def takeover_path() state_path + 'takeover' end
|
99
|
-
def
|
104
|
+
def endpoint_uri() URI.parse(method_missing('endpoint_uri')) end
|
105
|
+
def takeover_uri
|
106
|
+
result = endpoint_uri
|
107
|
+
result.path << TAKEOVER_PATH
|
108
|
+
result
|
109
|
+
end
|
100
110
|
|
101
111
|
def meta_data_hostname() @data['meta_data_hostname'] ||= meta_data('local-hostname') end
|
102
112
|
def meta_data_id() @data['meta_data_id'] ||= meta_data('instance-id') end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module EY
|
5
|
+
module Stonith
|
6
|
+
class Rackapp < Sinatra::Base
|
7
|
+
before { content_type :json }
|
8
|
+
get('/') { {}.to_json }
|
9
|
+
|
10
|
+
get HEALTH_PATH do
|
11
|
+
unless EY::Stonith.healthy?
|
12
|
+
status 503
|
13
|
+
end
|
14
|
+
{}.to_json
|
15
|
+
end
|
16
|
+
|
17
|
+
post TAKEOVER_PATH do
|
18
|
+
unless EY::Stonith.takeover(label, token)
|
19
|
+
status 410
|
20
|
+
end
|
21
|
+
{}.to_json
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def label() params['label'] end
|
27
|
+
def token() params['token'] end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/ey_stonith.rb
CHANGED
@@ -20,10 +20,34 @@ module EY
|
|
20
20
|
autoload :LocalMaster, 'ey_stonith/local_master'
|
21
21
|
autoload :Master, 'ey_stonith/master'
|
22
22
|
autoload :MetaData, 'ey_stonith/meta_data'
|
23
|
+
autoload :Rackapp, 'ey_stonith/rackapp'
|
23
24
|
autoload :Slave, 'ey_stonith/slave'
|
24
25
|
|
25
|
-
|
26
|
+
HEALTH_PATH = '/health' unless defined? HEALTH_PATH
|
27
|
+
TAKEOVER_PATH = '/takeover' unless defined? TAKEOVER_PATH
|
28
|
+
|
29
|
+
def self.log_to(io) @@logger = Logger.new io end
|
26
30
|
def self.logger() @@logger end
|
31
|
+
|
32
|
+
### For Rackapp ###
|
33
|
+
|
34
|
+
def self.healthy?() callback_module.healthy? end
|
35
|
+
|
36
|
+
def self.takeover(label, token)
|
37
|
+
if valid? label, token
|
38
|
+
callback_module.takeover label
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.valid?(label, token)
|
43
|
+
token_for(label) == token
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.token_for(label)
|
47
|
+
callback_module.token_for label
|
48
|
+
end
|
49
|
+
|
50
|
+
class << self; attr_accessor :callback_module end
|
27
51
|
end
|
28
52
|
end
|
29
53
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ezra Zygmuntowicz
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-05-06 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -59,6 +59,20 @@ dependencies:
|
|
59
59
|
name: redis
|
60
60
|
prerelease: false
|
61
61
|
type: :runtime
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
- 9
|
70
|
+
- 6
|
71
|
+
version: 0.9.6
|
72
|
+
requirement: *id004
|
73
|
+
name: sinatra
|
74
|
+
prerelease: false
|
75
|
+
type: :runtime
|
62
76
|
description: Shoot The Other Node In The Head
|
63
77
|
email: awsmdev@engineyard.com
|
64
78
|
executables:
|
@@ -103,6 +117,7 @@ files:
|
|
103
117
|
- lib/ey_stonith/data.rb
|
104
118
|
- lib/ey_stonith/database.rb
|
105
119
|
- lib/ey_stonith/history.rb
|
120
|
+
- lib/ey_stonith/rackapp.rb
|
106
121
|
- lib/ey_stonith.rb
|
107
122
|
- bin/stonith
|
108
123
|
- bin/stonith-check
|