bluepill 0.0.38 → 0.0.39
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bluepill.gemspec +3 -2
- data/lib/bluepill.rb +1 -2
- data/lib/bluepill/dsl.rb +3 -3
- data/lib/bluepill/process.rb +4 -1
- data/lib/bluepill/process_conditions.rb +1 -1
- data/lib/bluepill/process_conditions/http.rb +52 -0
- data/lib/bluepill/system.rb +4 -2
- data/lib/bluepill/version.rb +1 -1
- data/lib/example.rb +10 -26
- data/lib/runit_example.rb +13 -12
- metadata +5 -4
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.39
|
data/bluepill.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bluepill}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.39"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Arya Asemanfar", "Gary Tsang", "Rohith Ravi"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-02}
|
13
13
|
s.default_executable = %q{bluepill}
|
14
14
|
s.description = %q{Bluepill keeps your daemons up while taking up as little resources as possible. After all you probably want the resources of your server to be used by whatever daemons you are running rather than the thing that's supposed to make sure they are brought back up, should they die or misbehave.}
|
15
15
|
s.email = %q{entombedvirus@gmail.com}
|
@@ -41,6 +41,7 @@ Gem::Specification.new do |s|
|
|
41
41
|
"lib/bluepill/process_conditions.rb",
|
42
42
|
"lib/bluepill/process_conditions/always_true.rb",
|
43
43
|
"lib/bluepill/process_conditions/cpu_usage.rb",
|
44
|
+
"lib/bluepill/process_conditions/http.rb",
|
44
45
|
"lib/bluepill/process_conditions/mem_usage.rb",
|
45
46
|
"lib/bluepill/process_conditions/process_condition.rb",
|
46
47
|
"lib/bluepill/process_statistics.rb",
|
data/lib/bluepill.rb
CHANGED
@@ -9,7 +9,6 @@ require 'logger'
|
|
9
9
|
require 'active_support/inflector'
|
10
10
|
require 'active_support/core_ext/hash'
|
11
11
|
require 'active_support/core_ext/numeric'
|
12
|
-
require 'active_support/core_ext/object/misc'
|
13
12
|
require 'active_support/duration'
|
14
13
|
|
15
14
|
require 'bluepill/application'
|
@@ -29,4 +28,4 @@ require "bluepill/process_conditions"
|
|
29
28
|
|
30
29
|
require "bluepill/util/rotational_array"
|
31
30
|
|
32
|
-
require "bluepill/version"
|
31
|
+
require "bluepill/version"
|
data/lib/bluepill/dsl.rb
CHANGED
@@ -75,7 +75,7 @@ module Bluepill
|
|
75
75
|
@@process_proxy = process_proxy
|
76
76
|
@@process_keys = Hash.new # because I don't want to require Set just for validations
|
77
77
|
@@pid_files = Hash.new
|
78
|
-
attr_accessor :working_dir, :uid, :gid
|
78
|
+
attr_accessor :working_dir, :uid, :gid, :environment
|
79
79
|
|
80
80
|
def validate_process(process, process_name)
|
81
81
|
# validate uniqueness of group:process
|
@@ -127,7 +127,7 @@ module Bluepill
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def set_app_wide_attributes(process_proxy)
|
130
|
-
[:working_dir, :uid, :gid].each do |attribute|
|
130
|
+
[:working_dir, :uid, :gid, :environment].each do |attribute|
|
131
131
|
unless process_proxy.attributes.key?(attribute)
|
132
132
|
process_proxy.attributes[attribute] = self.send(attribute)
|
133
133
|
end
|
@@ -146,4 +146,4 @@ module Bluepill
|
|
146
146
|
yield(app_proxy.new)
|
147
147
|
app.load
|
148
148
|
end
|
149
|
-
end
|
149
|
+
end
|
data/lib/bluepill/process.rb
CHANGED
@@ -15,6 +15,7 @@ module Bluepill
|
|
15
15
|
:daemonize,
|
16
16
|
:pid_file,
|
17
17
|
:working_dir,
|
18
|
+
:environment,
|
18
19
|
|
19
20
|
:start_grace_time,
|
20
21
|
:stop_grace_time,
|
@@ -96,6 +97,7 @@ module Bluepill
|
|
96
97
|
# These defaults are overriden below if it's configured to be something else.
|
97
98
|
@monitor_children = false
|
98
99
|
@start_grace_time = @stop_grace_time = @restart_grace_time = 3
|
100
|
+
@environment = {}
|
99
101
|
|
100
102
|
CONFIGURABLE_ATTRIBUTES.each do |attribute_name|
|
101
103
|
self.send("#{attribute_name}=", options[attribute_name]) if options.has_key?(attribute_name)
|
@@ -390,6 +392,7 @@ module Bluepill
|
|
390
392
|
:uid => self.uid,
|
391
393
|
:gid => self.gid,
|
392
394
|
:working_dir => self.working_dir,
|
395
|
+
:environment => self.environment,
|
393
396
|
:pid_file => self.pid_file,
|
394
397
|
:logger => self.logger,
|
395
398
|
:stdin => self.stdin,
|
@@ -408,4 +411,4 @@ module Bluepill
|
|
408
411
|
end
|
409
412
|
end
|
410
413
|
end
|
411
|
-
|
414
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Bluepill
|
5
|
+
module ProcessConditions
|
6
|
+
class Http < ProcessCondition
|
7
|
+
def initialize(options = {})
|
8
|
+
@uri = URI.parse(options[:url])
|
9
|
+
@kind = case options[:kind]
|
10
|
+
when Fixnum then Net::HTTPResponse::CODE_TO_OBJ[options[:kind].to_s]
|
11
|
+
when String, Symbol then Net.const_get("HTTP#{options[:kind].to_s.camelize}")
|
12
|
+
else
|
13
|
+
Net::HTTPSuccess
|
14
|
+
end
|
15
|
+
@pattern = options[:pattern] || nil
|
16
|
+
@open_timeout = (options[:open_timeout] || options[:timeout] || 5).to_i
|
17
|
+
@read_timeout = (options[:read_timeout] || options[:timeout] || 5).to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
def run(pid)
|
21
|
+
session = Net::HTTP.new(@uri.host, @uri.port)
|
22
|
+
session.open_timeout = @open_timeout
|
23
|
+
session.read_timeout = @read_timeout
|
24
|
+
hide_net_http_bug do
|
25
|
+
session.start do |http|
|
26
|
+
http.get(@uri.path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
rescue
|
30
|
+
$!
|
31
|
+
end
|
32
|
+
|
33
|
+
def check(value)
|
34
|
+
return false unless value.kind_of?(@kind)
|
35
|
+
return true unless @pattern
|
36
|
+
return false unless value.class.body_permitted?
|
37
|
+
@pattern === value.body
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def hide_net_http_bug
|
42
|
+
yield
|
43
|
+
rescue NoMethodError => e
|
44
|
+
if e.to_s =~ /#{Regexp.escape(%q|undefined method `closed?' for nil:NilClass|)}/
|
45
|
+
raise Errno::ECONNREFUSED, "Connection refused attempting to contact #{@uri.scheme}://#{@uri.host}:#{@uri.port}"
|
46
|
+
else
|
47
|
+
raise
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/bluepill/system.rb
CHANGED
@@ -33,7 +33,7 @@ module Bluepill
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def get_children(parent_pid)
|
36
|
-
|
36
|
+
Array.new.tap do |child_pids|
|
37
37
|
ps_axu.each_pair do |pid, chunks|
|
38
38
|
child_pids << chunks[IDX_MAP[:pid]].to_i if chunks[IDX_MAP[:ppid]].to_i == parent_pid.to_i
|
39
39
|
end
|
@@ -68,6 +68,7 @@ module Bluepill
|
|
68
68
|
to_daemonize = lambda do
|
69
69
|
# Setting end PWD env emulates bash behavior when dealing with symlinks
|
70
70
|
Dir.chdir(ENV["PWD"] = options[:working_dir]) if options[:working_dir]
|
71
|
+
options[:environment].each { |key, value| ENV[key] = value } if options[:environment]
|
71
72
|
|
72
73
|
redirect_io(*options.values_at(:stdin, :stdout, :stderr))
|
73
74
|
|
@@ -114,6 +115,7 @@ module Bluepill
|
|
114
115
|
drop_privileges(options[:uid], options[:gid])
|
115
116
|
|
116
117
|
Dir.chdir(ENV["PWD"] = options[:working_dir]) if options[:working_dir]
|
118
|
+
options[:environment].each { |key, value| ENV[key] = value } if options[:environment]
|
117
119
|
|
118
120
|
# close unused fds so ancestors wont hang. This line is the only reason we are not
|
119
121
|
# using something like popen3. If this fd is not closed, the .read call on the parent
|
@@ -222,4 +224,4 @@ module Bluepill
|
|
222
224
|
end
|
223
225
|
end
|
224
226
|
end
|
225
|
-
end
|
227
|
+
end
|
data/lib/bluepill/version.rb
CHANGED
data/lib/example.rb
CHANGED
@@ -3,19 +3,10 @@ require 'bluepill'
|
|
3
3
|
require 'logger'
|
4
4
|
|
5
5
|
ROOT_DIR = "/tmp/bp"
|
6
|
-
Bluepill.define_process_condition(:always_false) do
|
7
|
-
def run(pid)
|
8
|
-
0
|
9
|
-
end
|
10
|
-
|
11
|
-
def check(value)
|
12
|
-
false
|
13
|
-
end
|
14
|
-
end
|
15
6
|
|
16
7
|
# Watch with
|
17
8
|
# watch -n0.2 'ps axu | egrep "(CPU|forking|bluepill|sleep)" | grep -v grep | sort'
|
18
|
-
Bluepill.application(:sample_app
|
9
|
+
Bluepill.application(:sample_app) do |app|
|
19
10
|
0.times do |i|
|
20
11
|
app.process("process_#{i}") do |process|
|
21
12
|
process.pid_file = "#{ROOT_DIR}/pids/process_#{i}.pid"
|
@@ -72,26 +63,19 @@ Bluepill.application(:sample_app, :foreground => true) do |app|
|
|
72
63
|
|
73
64
|
1.times do |i|
|
74
65
|
app.process("group_process_#{i}") do |process|
|
75
|
-
|
76
|
-
|
66
|
+
process.uid = "rohith"
|
67
|
+
process.gid = "wheel"
|
77
68
|
|
78
|
-
|
79
|
-
|
69
|
+
process.stderr = "/tmp/err.log"
|
70
|
+
process.stdout = "/tmp/err.log"
|
80
71
|
|
81
|
-
# process.group = "grouped"
|
82
|
-
process.monitor_children do |child_process|
|
83
|
-
child_process.stop_command = "kill -QUIT {{PID}}"
|
84
|
-
end
|
85
72
|
|
86
|
-
process.
|
87
|
-
process.
|
73
|
+
process.group = "grouped"
|
74
|
+
process.start_command = %Q{cd /tmp && ruby -e '$stderr.puts("hello stderr");$stdout.puts("hello stdout"); $stdout.flush; $stderr.flush; sleep 10'}
|
88
75
|
process.daemonize = true
|
89
|
-
process.pid_file = "/tmp/
|
90
|
-
|
91
|
-
process.checks :
|
92
|
-
process.checks :flapping, :times => 200, :within => 900.seconds, :retry_in => 7.seconds
|
93
|
-
process.checks :mem_usage, :every => 1, :below => 300.megabytes, :times => [3,5]
|
94
|
-
process.checks :cpu_usage, :every => 1, :below => 3000, :times => [3,5]
|
76
|
+
process.pid_file = "/tmp/noperm/p_#{process.group}_#{i}.pid"
|
77
|
+
|
78
|
+
# process.checks :always_true, :every => 5
|
95
79
|
end
|
96
80
|
end
|
97
81
|
end
|
data/lib/runit_example.rb
CHANGED
@@ -4,21 +4,22 @@ require 'logger'
|
|
4
4
|
|
5
5
|
# ATTENTION:
|
6
6
|
# You must declare only one application per config when foreground mode specified
|
7
|
+
#
|
8
|
+
# http://github.com/akzhan/runit-man used as example of monitored application.
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
app.process("opscode_agent") do |process|
|
12
|
-
process.pid_file = "/etc/service/opscode-agent/supervise/pid"
|
10
|
+
Bluepill.application(:runit_man, :foreground => true) do |app|
|
11
|
+
app.process("runit-man") do |process|
|
12
|
+
process.pid_file = "/etc/service/runit-man/supervise/pid"
|
13
13
|
|
14
|
-
process.start_command
|
15
|
-
process.stop_command
|
14
|
+
process.start_command = "/usr/bin/sv start runit-man"
|
15
|
+
process.stop_command = "/usr/bin/sv stop runit-man"
|
16
|
+
process.restart_command = "/usr/bin/sv restart runit-man"
|
16
17
|
|
17
|
-
process.start_grace_time
|
18
|
+
process.start_grace_time = 1.seconds
|
18
19
|
process.restart_grace_time = 7.seconds
|
19
|
-
process.stop_grace_time
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
process.stop_grace_time = 7.seconds
|
21
|
+
|
22
|
+
process.checks :http, :within => 30.seconds, :retry_in => 7.seconds, :every => 30.seconds,
|
23
|
+
:url => 'http://localhost:4567/', :kind => :success, :pattern => /html/, :timeout => 3.seconds
|
23
24
|
end
|
24
25
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bluepill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 81
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 39
|
10
|
+
version: 0.0.39
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Arya Asemanfar
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-
|
20
|
+
date: 2010-08-02 00:00:00 -07:00
|
21
21
|
default_executable: bluepill
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/bluepill/process_conditions.rb
|
118
118
|
- lib/bluepill/process_conditions/always_true.rb
|
119
119
|
- lib/bluepill/process_conditions/cpu_usage.rb
|
120
|
+
- lib/bluepill/process_conditions/http.rb
|
120
121
|
- lib/bluepill/process_conditions/mem_usage.rb
|
121
122
|
- lib/bluepill/process_conditions/process_condition.rb
|
122
123
|
- lib/bluepill/process_statistics.rb
|