heaven 0.0.12 → 0.0.13
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/VERSION +1 -1
- data/lib/heaven/god_watcher.rb +65 -39
- data/lib/heaven/heaven.rb +53 -4
- data/lib/heaven.rb +2 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.13
|
data/lib/heaven/god_watcher.rb
CHANGED
@@ -13,7 +13,7 @@ class GodWatcher # :nodoc:all
|
|
13
13
|
@interval = options[:interval] || 15.seconds
|
14
14
|
@grace = options[:grace] || 15.seconds
|
15
15
|
|
16
|
-
@behaviors = options[:behaviors] || [
|
16
|
+
@behaviors = options[:behaviors] || []
|
17
17
|
|
18
18
|
@max_memory = options[:max_memory] || 250.megabytes
|
19
19
|
@max_cpu = options[:max_cpu] || 50.percent
|
@@ -22,22 +22,24 @@ class GodWatcher # :nodoc:all
|
|
22
22
|
@check_flapping = options[:check_flapping].nil? ? true : options[:check_flapping]
|
23
23
|
@check_memory = options[:check_memory].nil? ? true : options[:check_memory]
|
24
24
|
@check_cpu = options[:check_cpu].nil? ? true : options[:check_cpu]
|
25
|
+
@check_url = options[:check_url].nil? ? false : options[:check_url]
|
25
26
|
|
26
|
-
@email_notifications
|
27
|
-
@
|
28
|
-
@
|
29
|
-
@
|
30
|
-
@
|
27
|
+
@email_notifications = options[:email_notifications] || false
|
28
|
+
@email_from_address = options[:email_from_address]
|
29
|
+
@email_from_name = options[:email_from_name] || "God"
|
30
|
+
@email_delivery_method = options[:email_delivery_method] || :sendmail
|
31
|
+
@email_to = options[:email_to] || []
|
31
32
|
|
32
33
|
@campfire_notifications = options[:campfire_notifications] || false
|
33
34
|
@campfire_subdomain = options[:campfire_subdomain]
|
34
35
|
@campfire_token = options[:campfire_token]
|
35
36
|
@campfire_room = options[:campfire_room]
|
37
|
+
|
38
|
+
@url = options[:url]
|
39
|
+
@url_timeout = options[:url_timeout] || 10.seconds
|
36
40
|
end
|
37
41
|
|
38
42
|
def watch
|
39
|
-
raise HeavenConfigurationError, "start command not specified" if @start.nil?
|
40
|
-
raise HeavenConfigurationError, "stop command not specified" if @stop.nil?
|
41
43
|
set_god_defaults unless @god_defaults_set
|
42
44
|
|
43
45
|
God.watch do |w|
|
@@ -48,35 +50,39 @@ class GodWatcher # :nodoc:all
|
|
48
50
|
w.restart = @restart if @restart # not mandatory, if we don't specify it god will do a stop and a start
|
49
51
|
w.pid_file = @pid_file if @pid_file
|
50
52
|
w.log = @log_file if @log_file
|
53
|
+
w.uid = @uid if @uid
|
54
|
+
w.gid = @gid if @gid
|
51
55
|
|
52
56
|
w.start_grace = @grace
|
53
57
|
w.restart_grace = @grace
|
54
58
|
|
55
59
|
@behaviors.each { |b| w.behavior(b) }
|
56
60
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
+
unless @check_url
|
62
|
+
# determine the state on startup
|
63
|
+
w.transition(:init, { true => :up, false => :start }) do |on|
|
64
|
+
on.condition(:process_running) do |c|
|
65
|
+
c.running = true
|
66
|
+
end
|
61
67
|
end
|
62
|
-
end
|
63
68
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
+
# determine when process has finished starting
|
70
|
+
w.transition([:start, :restart], :up) do |on|
|
71
|
+
on.condition(:process_running) do |c|
|
72
|
+
c.running = true
|
73
|
+
end
|
69
74
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
75
|
+
# failsafe
|
76
|
+
on.condition(:tries) do |c|
|
77
|
+
c.times = @max_times
|
78
|
+
c.transition = :start
|
79
|
+
end
|
74
80
|
end
|
75
|
-
end
|
76
81
|
|
77
|
-
|
78
|
-
|
79
|
-
|
82
|
+
# start if process is not running
|
83
|
+
w.transition(:up, :start) do |on|
|
84
|
+
on.condition(:process_exits)
|
85
|
+
end
|
80
86
|
end
|
81
87
|
|
82
88
|
if @check_memory || @check_cpu
|
@@ -98,15 +104,31 @@ class GodWatcher # :nodoc:all
|
|
98
104
|
end
|
99
105
|
end
|
100
106
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
107
|
+
if @check_url
|
108
|
+
u = URI.parse(@url)
|
109
|
+
w.transition(:up, :restart) do |on|
|
110
|
+
on.condition(:http_response_code) do |c|
|
111
|
+
c.host = u.host
|
112
|
+
c.port = u.port
|
113
|
+
c.path = u.path
|
114
|
+
c.code_is_not = 200
|
115
|
+
c.timeout = @url_timeout
|
116
|
+
c.times = @max_times
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
if @check_flapping
|
122
|
+
w.lifecycle do |check|
|
123
|
+
check.condition(:flapping) do |c|
|
124
|
+
c.to_state = [:start, :restart]
|
125
|
+
c.times = 5
|
126
|
+
c.within = 5.minutes
|
127
|
+
c.transition = :unmonitored
|
128
|
+
c.retry_in = 10.minutes
|
129
|
+
c.retry_times = 5
|
130
|
+
c.retry_within = 2.hours
|
131
|
+
end
|
110
132
|
end
|
111
133
|
end
|
112
134
|
end
|
@@ -117,12 +139,12 @@ class GodWatcher # :nodoc:all
|
|
117
139
|
|
118
140
|
if @email_notifications
|
119
141
|
God::Contacts::Email.defaults do |d|
|
120
|
-
d.from_email = @
|
121
|
-
d.from_name = @
|
122
|
-
d.delivery_method = @
|
142
|
+
d.from_email = @email_from_address
|
143
|
+
d.from_name = @email_from_name
|
144
|
+
d.delivery_method = @email_delivery_method
|
123
145
|
end
|
124
146
|
|
125
|
-
@
|
147
|
+
@email_to.each do |email|
|
126
148
|
God.contact(:email) do |c|
|
127
149
|
c.name = email
|
128
150
|
c.to_email = email
|
@@ -140,4 +162,8 @@ class GodWatcher # :nodoc:all
|
|
140
162
|
end
|
141
163
|
@god_defaults_set = true
|
142
164
|
end
|
165
|
+
|
166
|
+
def enforce(var, msg)
|
167
|
+
raise HeavenConfigurationError.new(msg) if var.blank?
|
168
|
+
end
|
143
169
|
end
|
data/lib/heaven/heaven.rb
CHANGED
@@ -25,13 +25,17 @@ class Heaven
|
|
25
25
|
# max_memory:: restart the service if its memory usage exceeds this much on [max_times] consecutive polls (default: 250.megabytes)
|
26
26
|
# max_cpu:: restart the service if its cpu usage exceeds this much on [max_times] consecutive polls (default: 50.percent)
|
27
27
|
# max_times:: see the above (default: 5)
|
28
|
-
def defaults(options)
|
29
|
-
|
28
|
+
def defaults(options=nil)
|
29
|
+
if options.nil?
|
30
|
+
@defaults || {}
|
31
|
+
else
|
32
|
+
@defaults = options
|
33
|
+
end
|
30
34
|
end
|
31
35
|
|
32
36
|
# Watch a run-of-the-mill UNIX daemon
|
33
37
|
#
|
34
|
-
# It
|
38
|
+
# It takes all the options available to defaults *and*:
|
35
39
|
# script:: name of the daemon's command script (it must take options stop, start and restart)
|
36
40
|
def watch_daemon(name, options = {})
|
37
41
|
script = options.delete(:script)
|
@@ -41,7 +45,52 @@ class Heaven
|
|
41
45
|
options[:restart] = "#{script} restart"
|
42
46
|
end
|
43
47
|
|
44
|
-
GodWatcher.new(name,
|
48
|
+
GodWatcher.new(name, defaults.merge(options)).watch
|
49
|
+
end
|
50
|
+
|
51
|
+
# Watch a mongrel Rails app
|
52
|
+
#
|
53
|
+
# It takes all the options available to defaults *and*:
|
54
|
+
#
|
55
|
+
# env:: environment to run under
|
56
|
+
# root:: application's root dir (e.g. /var/rails/myapp/current)
|
57
|
+
# pid_prefix:: the prefix of the pid file (takes something like tmp/pids/yourapp and looks for pids like tmp/pids/yourapp.12345.pid)
|
58
|
+
# log_prefix:: the prefix of the mongrel log file (takes something like log/yourapp and looks for logs like log/yourapp.12345.log)
|
59
|
+
# ports:: a list of ports the mongrels run on
|
60
|
+
def watch_mongrel(name, options = {})
|
61
|
+
env = options.delete(:env)
|
62
|
+
root = options.delete(:root)
|
63
|
+
pid_prefix = options.delete(:pid_prefix)
|
64
|
+
log_prefix = options.delete(:log_prefix)
|
65
|
+
ports = options.delete(:ports)
|
66
|
+
|
67
|
+
ports.each do |port|
|
68
|
+
mongrel_hash = {
|
69
|
+
:start => "mongrel_rails start -d -e #{env} -c #{root} -p #{port} -P #{root}/#{pid_prefix}.#{port}.pid -l #{root}/#{log_prefix}.#{port}.log",
|
70
|
+
:stop => "mongrel_rails stop -c #{root} -p #{port} -P #{root}/#{pid_prefix}.#{port}.pid",
|
71
|
+
:pid_file => "/var/rails/lessmemories/current/log/mongrel.#{port}.pid"
|
72
|
+
}
|
73
|
+
GodWatcher.new("#{name}-#{env}-#{port}", defaults.merge(mongrel_hash).merge(options)).watch
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Watch a URL
|
78
|
+
#
|
79
|
+
# It takes all the options available to defaults *and*:
|
80
|
+
#
|
81
|
+
# url:: the url to watch
|
82
|
+
# url_timeout:: how long to wait for a status
|
83
|
+
#
|
84
|
+
# Note that the start and stop options are ignored, this just restarts the service
|
85
|
+
def watch_url(name, options = {})
|
86
|
+
options[:check_cpu] = false
|
87
|
+
options[:check_memory] = false
|
88
|
+
options[:check_flapping] = false
|
89
|
+
options[:check_url] = true
|
90
|
+
|
91
|
+
options[:start] = ""
|
92
|
+
options[:stop] = ""
|
93
|
+
GodWatcher.new(name, defaults.merge(options)).watch
|
45
94
|
end
|
46
95
|
end
|
47
96
|
end
|
data/lib/heaven.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heaven
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 13
|
10
|
+
version: 0.0.13
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eugen Minciu
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-20 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|