quietus 0.0.1 → 1.0.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.
- checksums.yaml +4 -4
- data/.travis.yml +10 -0
- data/README.md +33 -1
- data/Rakefile +9 -1
- data/lib/quietus/version.rb +1 -1
- data/lib/quietus.rb +5 -19
- data/quietus.gemspec +2 -0
- data/spec/quietus_spec.rb +40 -0
- data/spec/spec_helper.rb +4 -0
- metadata +32 -2
- data/LICENSE.txt +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3a5cc3af003537f8103ca7f78e41d5a38fdec69
|
4
|
+
data.tar.gz: 9e34862bc1838775b621a9d909c220a9a7f0379d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f91b27aed0aa89614aec2a1c2ebb601695612bb698b541c56a7ae244b3593d7ca485e3b36451affb865fa7dbe71660e25577ff0a58a8ace575ff96e4e3d7793
|
7
|
+
data.tar.gz: 9661023616de348ab98c430dac8e2f1bd0427cf69d0f07c8a866a0ca1846a3ac20e5c0c94c917fea119eb5ae2d576e8079d9b71c9a5fb67e79d53d8dc11c7976
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,36 @@
|
|
1
|
-
|
1
|
+
Quietus
|
2
2
|
=======
|
3
3
|
|
4
4
|
Simple status check web server.
|
5
|
+
|
6
|
+
[](https://travis-ci.org/BBC-News/quietus) [](http://badge.fury.io/rb/quietus)
|
7
|
+
|
8
|
+
##Why
|
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.
|
11
|
+
|
12
|
+
See these [AWS Docs](http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/as-maintain-instance-levels.html).
|
13
|
+
|
14
|
+
##Usage
|
15
|
+
|
16
|
+
```rb
|
17
|
+
require 'quietus'
|
18
|
+
|
19
|
+
optional_hostname = 'localhost'
|
20
|
+
optional_port = '2347'
|
21
|
+
|
22
|
+
# quietus runs your check in a loop, so you might want to sleep
|
23
|
+
def your_status_check
|
24
|
+
sleep 1
|
25
|
+
is_my_app_healthy?
|
26
|
+
end
|
27
|
+
|
28
|
+
# quietus is blocking so you might want to run it in a thread or fork depending on your Ruby version
|
29
|
+
t = Thread.new do
|
30
|
+
Quietus::Server.new(optional_hostname, optional_port) { your_status_check }
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
**The Quietus server will return a 200 if your_status_check is truthy, 500 otherwise**
|
35
|
+
|
36
|
+
By default quietus runs on port 2347.
|
data/Rakefile
CHANGED
data/lib/quietus/version.rb
CHANGED
data/lib/quietus.rb
CHANGED
@@ -6,8 +6,8 @@ module Quietus
|
|
6
6
|
attr_reader :port, :hostname
|
7
7
|
|
8
8
|
def initialize(hostname = 'localhost', port = 2347)
|
9
|
-
@hostname
|
10
|
-
@port
|
9
|
+
@hostname = hostname
|
10
|
+
@port = port
|
11
11
|
|
12
12
|
server &Proc.new
|
13
13
|
end
|
@@ -15,25 +15,11 @@ module Quietus
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def server(&proc)
|
18
|
-
|
19
|
-
|
20
|
-
loop do
|
21
|
-
socket = tcp_server.accept
|
22
|
-
|
23
|
-
socket.gets
|
24
|
-
respond(socket, proc)
|
25
|
-
socket.close
|
26
|
-
end
|
18
|
+
loop { respond if proc.call }
|
27
19
|
end
|
28
20
|
|
29
|
-
def respond
|
30
|
-
|
31
|
-
socket.print "HTTP/1.0 #{response}\r\n" +
|
32
|
-
"Content-Type: text/plain\r\n" +
|
33
|
-
"Content-Length: #{response.bytesize}\r\n" +
|
34
|
-
"Connection: close\r\n"
|
35
|
-
socket.print "\r\n"
|
36
|
-
socket.print "#{response}"
|
21
|
+
def respond
|
22
|
+
TCPServer.open(hostname, port) { |s| s.accept.close }
|
37
23
|
end
|
38
24
|
end
|
39
25
|
end
|
data/quietus.gemspec
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
describe Quietus::Server do
|
5
|
+
context "creating" do
|
6
|
+
|
7
|
+
context "passed a falsy block" do
|
8
|
+
it "refuses a TCP connection" do
|
9
|
+
pid = fork do
|
10
|
+
Signal.trap("HUP") { exit }
|
11
|
+
Quietus::Server.new { false }
|
12
|
+
end
|
13
|
+
|
14
|
+
sleep 1
|
15
|
+
|
16
|
+
expect { TCPSocket.new('localhost', 2347) }.to raise_error(Errno::ECONNREFUSED)
|
17
|
+
|
18
|
+
Process.kill("HUP", pid)
|
19
|
+
Process.wait
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "passed a truthy block" do
|
24
|
+
it "allows a TCP connection" do
|
25
|
+
pid = fork do
|
26
|
+
Signal.trap("HUP") { exit }
|
27
|
+
Quietus::Server.new { true }
|
28
|
+
end
|
29
|
+
|
30
|
+
sleep 1
|
31
|
+
|
32
|
+
expect { TCPSocket.new('localhost', 2347) }.not_to raise_error
|
33
|
+
|
34
|
+
Process.kill("HUP", pid)
|
35
|
+
Process.wait
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quietus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Kenny
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
description:
|
42
70
|
email:
|
43
71
|
- kenoir@gmail.com
|
@@ -46,14 +74,16 @@ extensions: []
|
|
46
74
|
extra_rdoc_files: []
|
47
75
|
files:
|
48
76
|
- .gitignore
|
77
|
+
- .travis.yml
|
49
78
|
- Gemfile
|
50
79
|
- LICENSE
|
51
|
-
- LICENSE.txt
|
52
80
|
- README.md
|
53
81
|
- Rakefile
|
54
82
|
- lib/quietus.rb
|
55
83
|
- lib/quietus/version.rb
|
56
84
|
- quietus.gemspec
|
85
|
+
- spec/quietus_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
57
87
|
homepage: https://github.com/kenoir/quietus
|
58
88
|
licenses:
|
59
89
|
- GPLv3
|
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2014 Robert Kenny
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|