jnewland-pulse 0.4.1
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/README.textile +108 -0
- data/init.rb +1 -0
- data/lib/pulse.rb +3 -0
- data/lib/pulse_controller.rb +19 -0
- data/lib/pulse_helper.rb +2 -0
- data/lib/routes.rb +9 -0
- metadata +67 -0
data/README.textile
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
h1. Pulse
|
|
2
|
+
|
|
3
|
+
Pulse adds an action to your rails project that can be used for external health checking. The most common use is by a http proxy such as "haproxy":http://haproxy.1wt.eu/ or a monitoring tool such as "god":http://god.rubyforge.org.
|
|
4
|
+
|
|
5
|
+
h3. Authors
|
|
6
|
+
|
|
7
|
+
* "Paul Gross":http://www.prgs.net
|
|
8
|
+
* "Jesse Newland":http://jnewland.com
|
|
9
|
+
|
|
10
|
+
h2. Requirements
|
|
11
|
+
|
|
12
|
+
* Rails
|
|
13
|
+
* MySQL, Postgres, or Oracle. sqlite not supported, sorry.
|
|
14
|
+
|
|
15
|
+
h2. Installation
|
|
16
|
+
|
|
17
|
+
In your @config/environment.rb@:
|
|
18
|
+
|
|
19
|
+
<pre>
|
|
20
|
+
<code>
|
|
21
|
+
config.gem 'jnewland_pulse', :lib => 'pulse', :source => 'http://gems.github.com'
|
|
22
|
+
</code>
|
|
23
|
+
</pre>
|
|
24
|
+
|
|
25
|
+
Install the gem:
|
|
26
|
+
|
|
27
|
+
<pre>
|
|
28
|
+
<code>
|
|
29
|
+
cd RAILS_ROOT
|
|
30
|
+
rake gems:install
|
|
31
|
+
</code>
|
|
32
|
+
</pre>
|
|
33
|
+
|
|
34
|
+
Finally, add a route to config/routes.rb:
|
|
35
|
+
|
|
36
|
+
<pre>
|
|
37
|
+
<code>
|
|
38
|
+
map.pulse 'pulse'
|
|
39
|
+
</code>
|
|
40
|
+
</pre>
|
|
41
|
+
|
|
42
|
+
This configures pulse to work at the 'pulse' URL. If you would rather use a different URL:
|
|
43
|
+
|
|
44
|
+
<pre>
|
|
45
|
+
<code>
|
|
46
|
+
map.pulse 'some/other/url'
|
|
47
|
+
</code>
|
|
48
|
+
</pre>
|
|
49
|
+
|
|
50
|
+
h2. haproxy configuration
|
|
51
|
+
|
|
52
|
+
haproxy can be configured to use the /pulse url for its health checking. Just add:
|
|
53
|
+
|
|
54
|
+
<pre>
|
|
55
|
+
<code>
|
|
56
|
+
option httpchk GET /pulse
|
|
57
|
+
</code>
|
|
58
|
+
</pre>
|
|
59
|
+
|
|
60
|
+
You can adjust the interval and grace period for this check with the @check inter@ and @slowstart@ options. Since mongrel won't respond to HTTP requests until the entire Rails environment is loaded, this is essential.
|
|
61
|
+
|
|
62
|
+
<pre>
|
|
63
|
+
<code>
|
|
64
|
+
listen rails :9000
|
|
65
|
+
server rails-1 localhost:8000 maxconn 1 check inter 20000 slowstart 90000
|
|
66
|
+
server rails-2 localhost:8001 maxconn 1 check inter 20000 slowstart 90000
|
|
67
|
+
...
|
|
68
|
+
</code>
|
|
69
|
+
</pre>
|
|
70
|
+
|
|
71
|
+
h2. god configuration
|
|
72
|
+
|
|
73
|
+
You are using god to watch your mongrels, right?
|
|
74
|
+
|
|
75
|
+
In your mongrel watch, add the following restart condition:
|
|
76
|
+
|
|
77
|
+
<pre>
|
|
78
|
+
<code>
|
|
79
|
+
w.restart_if do |restart|
|
|
80
|
+
...
|
|
81
|
+
restart.condition(:http_response_code) do |c|
|
|
82
|
+
c.code_is_not = 200
|
|
83
|
+
c.host = 'localhost'
|
|
84
|
+
c.path = '/pulse'
|
|
85
|
+
c.port = 8000
|
|
86
|
+
c.timeout = 5.seconds
|
|
87
|
+
c.interval = 20.seconds
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
</code>
|
|
91
|
+
</pre>
|
|
92
|
+
|
|
93
|
+
Also make sure to give your mongrels a nice grace period.
|
|
94
|
+
|
|
95
|
+
<pre>
|
|
96
|
+
<code>
|
|
97
|
+
...
|
|
98
|
+
w.start_grace = 90.seconds
|
|
99
|
+
w.restart_grace = 90.seconds
|
|
100
|
+
...
|
|
101
|
+
</code>
|
|
102
|
+
</pre>
|
|
103
|
+
|
|
104
|
+
For a complete god configuration example, check out my "god_examples project":http://github.com/jnewland/god_examples and the included "sample rails god config":http://github.com/jnewland/god_examples/tree/master/rails/config/god/app.god.
|
|
105
|
+
|
|
106
|
+
h2. License
|
|
107
|
+
|
|
108
|
+
Released under "Ruby's license":http://www.ruby-lang.org/en/LICENSE.txt
|
data/init.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + "/lib/pulse"
|
data/lib/pulse.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class PulseController < ActionController::Base
|
|
2
|
+
session :off
|
|
3
|
+
|
|
4
|
+
#The pulse action. Runs <tt>select 1</tt> on the DB. If a sane result is
|
|
5
|
+
#returned, 'OK' is displayed and a 200 response code is returned. If not,
|
|
6
|
+
#'ERROR' is returned along with a 500 response code.
|
|
7
|
+
def pulse
|
|
8
|
+
if (ActiveRecord::Base.connection.execute("select 1 from dual").num_rows rescue 0) == 1
|
|
9
|
+
render :text => "<html><body>OK #{Time.now.utc.to_s(:db)}</body></html>"
|
|
10
|
+
else
|
|
11
|
+
render :text => '<html><body>ERROR</body></html>', :status => :internal_server_error
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
#cancel out loggin for the PulseController by defining logger as <tt>nil</tt>
|
|
16
|
+
def logger
|
|
17
|
+
nil
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/pulse_helper.rb
ADDED
data/lib/routes.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jnewland-pulse
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.4.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Paul Gross
|
|
8
|
+
- Jesse Newland
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
|
|
13
|
+
date: 2008-10-03 00:00:00 -07:00
|
|
14
|
+
default_executable:
|
|
15
|
+
dependencies:
|
|
16
|
+
- !ruby/object:Gem::Dependency
|
|
17
|
+
name: rails
|
|
18
|
+
version_requirement:
|
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
20
|
+
requirements:
|
|
21
|
+
- - ">="
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: "0"
|
|
24
|
+
version:
|
|
25
|
+
description: Adds a pulse action to a Rails app
|
|
26
|
+
email: jnewland@gmail.com
|
|
27
|
+
executables: []
|
|
28
|
+
|
|
29
|
+
extensions: []
|
|
30
|
+
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
|
|
33
|
+
files:
|
|
34
|
+
- init.rb
|
|
35
|
+
- lib/pulse.rb
|
|
36
|
+
- lib/pulse_controller.rb
|
|
37
|
+
- lib/pulse_helper.rb
|
|
38
|
+
- lib/routes.rb
|
|
39
|
+
- README.textile
|
|
40
|
+
has_rdoc: false
|
|
41
|
+
homepage: http://github.com/jnewland/pulse
|
|
42
|
+
post_install_message:
|
|
43
|
+
rdoc_options: []
|
|
44
|
+
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: "0"
|
|
52
|
+
version:
|
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: "0"
|
|
58
|
+
version:
|
|
59
|
+
requirements: []
|
|
60
|
+
|
|
61
|
+
rubyforge_project:
|
|
62
|
+
rubygems_version: 1.2.0
|
|
63
|
+
signing_key:
|
|
64
|
+
specification_version: 2
|
|
65
|
+
summary: Adds a pulse action to a Rails app
|
|
66
|
+
test_files: []
|
|
67
|
+
|