quietus 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -6
- data/lib/quietus/active_server.rb +29 -0
- data/lib/quietus/passive_server.rb +28 -0
- data/lib/quietus/version.rb +1 -1
- data/lib/quietus.rb +4 -21
- data/spec/active_server_spec.rb +42 -0
- data/spec/{quietus_spec.rb → passive_server_spec.rb} +4 -3
- data/spec/spec_helper.rb +2 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d8410205dbca9178b2609a1a76788fdab743cba
|
4
|
+
data.tar.gz: fd7fa1a795b0eeff504db7dc6ef8f7f40b2c641f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78dc5a4bd4def6ea16a223bf42328eea730e796f9bce5cd7a59e3f27730b9ca9ed8f68a7c73ed335a3637a93f32046a4189887c2c452968084d5c179d7af1085
|
7
|
+
data.tar.gz: 4a94d9417bc062b259cc391934bd4a4f71207e7cc34b37098d4d1cf719927481a2d16dcb2a062aa4d416f3f554e28643a050576e348b99e29a8c075d982b7d5c
|
data/README.md
CHANGED
@@ -7,17 +7,25 @@ Simple status check web server.
|
|
7
7
|
|
8
8
|
##Why
|
9
9
|
|
10
|
-
You might want to use this to provide a status check to an AWS ELB where you don't have a web server in your app. Having a status check lets you quietly kill unhealthy instances and replace them.
|
10
|
+
You might want to use this to provide a status check to an AWS ELB where you don't have a web server in your app. Having a status check lets you quietly kill unhealthy instances and replace them.
|
11
11
|
|
12
|
-
See these
|
12
|
+
See these AWS Docs
|
13
|
+
- [Maintainging instance levels](http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/as-maintain-instance-levels.html)
|
14
|
+
- [Health check API](http://docs.aws.amazon.com/ElasticLoadBalancing/latest/APIReference/API_HealthCheck.html)
|
15
|
+
- [Configure the Health state of an instance](http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/as-configure-healthcheck.html)
|
13
16
|
|
14
17
|
##Usage
|
15
18
|
|
19
|
+
###Passive (TCP Server only)
|
20
|
+
|
21
|
+
This setup requires you to have an ELB setup monitoring the specified port for a
|
22
|
+
TCP response.
|
23
|
+
|
16
24
|
```rb
|
17
25
|
require 'quietus'
|
18
26
|
|
19
|
-
|
20
|
-
|
27
|
+
hostname = 'localhost'
|
28
|
+
port = '2347'
|
21
29
|
|
22
30
|
# quietus runs your check in a loop, so you might want to sleep
|
23
31
|
def your_status_check
|
@@ -27,10 +35,40 @@ end
|
|
27
35
|
|
28
36
|
# quietus is blocking so you might want to run it in a thread or fork depending on your Ruby version
|
29
37
|
t = Thread.new do
|
30
|
-
Quietus::
|
38
|
+
Quietus::PassiveServer.new(optional_hostname, optional_port) { your_status_check }
|
31
39
|
end
|
32
40
|
```
|
33
41
|
|
34
|
-
**The Quietus server will
|
42
|
+
**The Passive Quietus server will accept a TCP connection if your_status_check is truthy, otherwise it will refuse**
|
35
43
|
|
36
44
|
By default quietus runs on port 2347.
|
45
|
+
|
46
|
+
###Active (uses AWS SDK to contact Health Check API)
|
47
|
+
|
48
|
+
This setup will actively contact AWS to update instance health. Use this if you
|
49
|
+
don't want an ELB.
|
50
|
+
|
51
|
+
```rb
|
52
|
+
require 'quietus'
|
53
|
+
require 'aws-sdk'
|
54
|
+
|
55
|
+
# You'll need to get an auto_scaling_instance from the API
|
56
|
+
auto_scaling = AWS::AutoScaling.new
|
57
|
+
auto_scaling_instance = auto_scaling.instances['i-12345678']
|
58
|
+
|
59
|
+
# quietus runs your check in a loop, so you might want to sleep
|
60
|
+
def your_status_check
|
61
|
+
sleep 1
|
62
|
+
is_my_app_healthy?
|
63
|
+
end
|
64
|
+
|
65
|
+
# quietus is blocking so you might want to run it in a thread or fork depending on your Ruby version
|
66
|
+
t = Thread.new do
|
67
|
+
Quietus::ActiveServer.new(auto_scaling_instance) { your_status_check }
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
**It's important to remember if your app simply crashes, using the active setup
|
72
|
+
the health check API won't get updated.**
|
73
|
+
|
74
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Quietus
|
2
|
+
class ActiveServer
|
3
|
+
attr_reader :instance_id, :respect_grace_period, :status
|
4
|
+
|
5
|
+
def initialize(auto_scaling_instance, respect_grace_period = true)
|
6
|
+
@respect_grace_period = respect_grace_period
|
7
|
+
@auto_scaling_instance = auto_scaling_instance
|
8
|
+
|
9
|
+
server &Proc.new
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def server(&proc)
|
15
|
+
loop do
|
16
|
+
new_status = proc.call
|
17
|
+
update new_status if new_status != status
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def update(status)
|
22
|
+
@auto_scaling_instance.set_health(
|
23
|
+
status ? 'Healthy' : 'Unhealthy',
|
24
|
+
:should_respect_grace_period => respect_grace_period
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "socket"
|
2
|
+
|
3
|
+
module Quietus
|
4
|
+
class PassiveServer
|
5
|
+
attr_reader :port, :hostname
|
6
|
+
|
7
|
+
DEFAULT_HOSTNAME = 'localhost'
|
8
|
+
DEFAULT_PORT = 2347
|
9
|
+
|
10
|
+
def initialize(hostname = nil, port = nil)
|
11
|
+
@hostname = hostname || DEFAULT_HOSTNAME
|
12
|
+
@port = port || DEFAULT_PORT
|
13
|
+
|
14
|
+
server &Proc.new
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def server(&proc)
|
20
|
+
loop { respond if proc.call }
|
21
|
+
end
|
22
|
+
|
23
|
+
def respond
|
24
|
+
TCPServer.open(hostname, port) { |s| s.accept.close }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/lib/quietus/version.rb
CHANGED
data/lib/quietus.rb
CHANGED
@@ -1,26 +1,9 @@
|
|
1
1
|
require "quietus/version"
|
2
|
-
require "socket"
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
attr_reader :port, :hostname
|
7
|
-
|
8
|
-
def initialize(hostname = 'localhost', port = 2347)
|
9
|
-
@hostname = hostname
|
10
|
-
@port = port
|
11
|
-
|
12
|
-
server &Proc.new
|
13
|
-
end
|
3
|
+
require "quietus/active_server"
|
4
|
+
require "quietus/passive_server"
|
14
5
|
|
15
|
-
|
16
|
-
|
17
|
-
def server(&proc)
|
18
|
-
loop { respond if proc.call }
|
19
|
-
end
|
20
|
-
|
21
|
-
def respond
|
22
|
-
TCPServer.open(hostname, port) { |s| s.accept.close }
|
23
|
-
end
|
24
|
-
end
|
6
|
+
module Quietus
|
7
|
+
# Space left deliberatly blank
|
25
8
|
end
|
26
9
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Quietus::ActiveServer do
|
4
|
+
context "creating" do
|
5
|
+
context "passed a truthy block" do
|
6
|
+
it "updates instance health to 'Healthy'" do
|
7
|
+
aws_instance = double('instance')
|
8
|
+
aws_instance.should_receive(:set_health).with(
|
9
|
+
'Healthy',
|
10
|
+
{
|
11
|
+
:should_respect_grace_period => true
|
12
|
+
}
|
13
|
+
).and_raise RspecLoopStop
|
14
|
+
|
15
|
+
begin
|
16
|
+
Quietus::ActiveServer.new(aws_instance) { true }
|
17
|
+
rescue RspecLoopStop
|
18
|
+
# Done
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "passed a falsy block" do
|
24
|
+
it "updates instance health to 'Unhealthy'" do
|
25
|
+
aws_instance = double('instance')
|
26
|
+
aws_instance.should_receive(:set_health).with(
|
27
|
+
'Unhealthy',
|
28
|
+
{
|
29
|
+
:should_respect_grace_period => true
|
30
|
+
}
|
31
|
+
).and_raise RspecLoopStop
|
32
|
+
|
33
|
+
begin
|
34
|
+
Quietus::ActiveServer.new(aws_instance) { false }
|
35
|
+
rescue RspecLoopStop
|
36
|
+
# Done
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'socket'
|
3
3
|
|
4
|
-
describe Quietus::
|
4
|
+
describe Quietus::PassiveServer do
|
5
5
|
context "creating" do
|
6
6
|
|
7
7
|
context "passed a falsy block" do
|
8
8
|
it "refuses a TCP connection" do
|
9
9
|
pid = fork do
|
10
10
|
Signal.trap("HUP") { exit }
|
11
|
-
Quietus::
|
11
|
+
Quietus::PassiveServer.new { false }
|
12
12
|
end
|
13
13
|
|
14
14
|
sleep 1
|
@@ -24,7 +24,7 @@ describe Quietus::Server do
|
|
24
24
|
it "allows a TCP connection" do
|
25
25
|
pid = fork do
|
26
26
|
Signal.trap("HUP") { exit }
|
27
|
-
Quietus::
|
27
|
+
Quietus::PassiveServer.new { true }
|
28
28
|
end
|
29
29
|
|
30
30
|
sleep 1
|
@@ -38,3 +38,4 @@ describe Quietus::Server do
|
|
38
38
|
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quietus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Kenny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,9 +80,12 @@ files:
|
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
82
|
- lib/quietus.rb
|
83
|
+
- lib/quietus/active_server.rb
|
84
|
+
- lib/quietus/passive_server.rb
|
83
85
|
- lib/quietus/version.rb
|
84
86
|
- quietus.gemspec
|
85
|
-
- spec/
|
87
|
+
- spec/active_server_spec.rb
|
88
|
+
- spec/passive_server_spec.rb
|
86
89
|
- spec/spec_helper.rb
|
87
90
|
homepage: https://github.com/kenoir/quietus
|
88
91
|
licenses:
|