bluepill 0.0.44 → 0.0.45
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -4
- data/Rakefile +3 -1
- data/VERSION +1 -1
- data/bin/bluepill +4 -0
- data/bluepill.gemspec +5 -5
- data/lib/bluepill/application.rb +1 -1
- data/lib/bluepill/application/server.rb +3 -5
- data/lib/bluepill/process.rb +4 -1
- data/lib/bluepill/process_conditions/http.rb +6 -1
- data/lib/bluepill/system.rb +4 -3
- data/lib/bluepill/trigger.rb +11 -2
- data/lib/bluepill/triggers/flapping.rb +4 -6
- data/lib/bluepill/version.rb +1 -1
- data/lib/example.rb +3 -3
- metadata +12 -4
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
Bluepill is a simple process monitoring tool written in Ruby.
|
3
3
|
|
4
4
|
## Installation
|
5
|
-
It
|
5
|
+
It's hosted on [gemcutter.org][gemcutter].
|
6
6
|
|
7
7
|
sudo gem install bluepill
|
8
8
|
|
@@ -10,7 +10,7 @@ In order to take advantage of logging with syslog, you also need to setup your s
|
|
10
10
|
|
11
11
|
local6.* /var/log/bluepill.log
|
12
12
|
|
13
|
-
You
|
13
|
+
You'll also want to add _/var/log/bluepill.log_ to _/etc/logrotate.d/syslog_ so that it gets rotated.
|
14
14
|
|
15
15
|
Lastly, create the _/var/bluepill_ directory for bluepill to store its pid and sock files.
|
16
16
|
|
@@ -37,7 +37,7 @@ Note that since we specified a PID file and start command, bluepill assumes the
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
If you don
|
40
|
+
If you don't specify a stop command, a TERM signal will be sent by default. Similarly, the default restart action is to issue stop and then start.
|
41
41
|
|
42
42
|
Now if we want to do something more meaningful, like actually monitor the process, we do:
|
43
43
|
|
@@ -203,7 +203,7 @@ To quit bluepill:
|
|
203
203
|
sudo bluepill quit
|
204
204
|
|
205
205
|
### Logging
|
206
|
-
By default, bluepill uses syslog local6 facility as described in the installation section. But if for any reason you don
|
206
|
+
By default, bluepill uses syslog local6 facility as described in the installation section. But if for any reason you don't want to use syslog, you can use a log file. You can do this by setting the :log\_file option in the config:
|
207
207
|
|
208
208
|
Bluepill.application("app_name", :log_file => "/path/to/bluepill.log") do |app|
|
209
209
|
# ...
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require 'rake'
|
3
5
|
|
@@ -13,7 +15,7 @@ begin
|
|
13
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
16
|
gem.add_dependency("daemons", ">= 1.0.9")
|
15
17
|
gem.add_dependency("blankslate", ">= 2.1.2.2")
|
16
|
-
gem.add_dependency("state_machine", ">= 0.8.0")
|
18
|
+
gem.add_dependency("state_machine", ">= 0.8.0", "<=0.9.4")
|
17
19
|
gem.add_dependency("activesupport", ">= 2.3.4")
|
18
20
|
|
19
21
|
gem.files -= ["bin/sample_forking_server"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.45
|
data/bin/bluepill
CHANGED
@@ -28,6 +28,10 @@ OptionParser.new do |opts|
|
|
28
28
|
options[:privileged] = v
|
29
29
|
end
|
30
30
|
|
31
|
+
opts.on('-t', '--timeout Seconds', Integer, "Timeout for commands sent to the daemon, in seconds. Defaults to 10.") do |timeout|
|
32
|
+
options[:timeout] = timeout
|
33
|
+
end
|
34
|
+
|
31
35
|
help = proc do
|
32
36
|
puts opts
|
33
37
|
puts
|
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.45"
|
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{
|
12
|
+
s.date = %q{2011-03-24}
|
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}
|
@@ -67,18 +67,18 @@ Gem::Specification.new do |s|
|
|
67
67
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
68
68
|
s.add_runtime_dependency(%q<daemons>, [">= 1.0.9"])
|
69
69
|
s.add_runtime_dependency(%q<blankslate>, [">= 2.1.2.2"])
|
70
|
-
s.add_runtime_dependency(%q<state_machine>, [">= 0.8.0"])
|
70
|
+
s.add_runtime_dependency(%q<state_machine>, [">= 0.8.0", "<= 0.9.4"])
|
71
71
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
|
72
72
|
else
|
73
73
|
s.add_dependency(%q<daemons>, [">= 1.0.9"])
|
74
74
|
s.add_dependency(%q<blankslate>, [">= 2.1.2.2"])
|
75
|
-
s.add_dependency(%q<state_machine>, [">= 0.8.0"])
|
75
|
+
s.add_dependency(%q<state_machine>, [">= 0.8.0", "<= 0.9.4"])
|
76
76
|
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
77
77
|
end
|
78
78
|
else
|
79
79
|
s.add_dependency(%q<daemons>, [">= 1.0.9"])
|
80
80
|
s.add_dependency(%q<blankslate>, [">= 2.1.2.2"])
|
81
|
-
s.add_dependency(%q<state_machine>, [">= 0.8.0"])
|
81
|
+
s.add_dependency(%q<state_machine>, [">= 0.8.0", "<= 0.9.4"])
|
82
82
|
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
83
83
|
end
|
84
84
|
end
|
data/lib/bluepill/application.rb
CHANGED
@@ -3,11 +3,9 @@ module Bluepill
|
|
3
3
|
module ServerMethods
|
4
4
|
|
5
5
|
def status
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
buffer
|
6
|
+
self.processes.collect do |process|
|
7
|
+
"#{process.name} #{process.state}"
|
8
|
+
end.join("\n")
|
11
9
|
end
|
12
10
|
|
13
11
|
def restart
|
data/lib/bluepill/process.rb
CHANGED
@@ -340,6 +340,7 @@ module Bluepill
|
|
340
340
|
|
341
341
|
def unlink_pid
|
342
342
|
File.unlink(pid_file) if pid_file && File.exists?(pid_file)
|
343
|
+
rescue Errno::ENOENT
|
343
344
|
end
|
344
345
|
|
345
346
|
# Internal State Methods
|
@@ -382,10 +383,12 @@ module Bluepill
|
|
382
383
|
def deep_copy
|
383
384
|
# TODO: This is a kludge. Ideally, process templates
|
384
385
|
# would be facotries, and not a template object.
|
385
|
-
mutex, @event_mutex = @event_mutex, nil
|
386
|
+
mutex, triggers, @event_mutex, @triggers = @event_mutex, @triggers, nil, nil
|
386
387
|
clone = Marshal.load(Marshal.dump(self))
|
387
388
|
clone.instance_variable_set("@event_mutex", Monitor.new)
|
389
|
+
clone.instance_variable_set("@triggers", triggers.collect{ |t| t.deep_copy })
|
388
390
|
@event_mutex = mutex
|
391
|
+
@triggers = triggers
|
389
392
|
clone
|
390
393
|
end
|
391
394
|
|
@@ -19,6 +19,11 @@ module Bluepill
|
|
19
19
|
|
20
20
|
def run(pid)
|
21
21
|
session = Net::HTTP.new(@uri.host, @uri.port)
|
22
|
+
if @uri.scheme == 'https'
|
23
|
+
require 'net/https'
|
24
|
+
session.use_ssl=true
|
25
|
+
session.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
26
|
+
end
|
22
27
|
session.open_timeout = @open_timeout
|
23
28
|
session.read_timeout = @read_timeout
|
24
29
|
hide_net_http_bug do
|
@@ -49,4 +54,4 @@ module Bluepill
|
|
49
54
|
end
|
50
55
|
end
|
51
56
|
end
|
52
|
-
end
|
57
|
+
end
|
data/lib/bluepill/system.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'etc'
|
2
|
+
require "shellwords"
|
2
3
|
|
3
4
|
module Bluepill
|
4
5
|
# This class represents the system that bluepill is running on.. It's mainly used to memoize
|
@@ -72,7 +73,7 @@ module Bluepill
|
|
72
73
|
|
73
74
|
redirect_io(*options.values_at(:stdin, :stdout, :stderr))
|
74
75
|
|
75
|
-
::Kernel.exec(cmd)
|
76
|
+
::Kernel.exec(*Shellwords.shellwords(cmd))
|
76
77
|
exit
|
77
78
|
end
|
78
79
|
|
@@ -136,7 +137,7 @@ module Bluepill
|
|
136
137
|
cmd_err_write.close
|
137
138
|
|
138
139
|
# finally, replace grandchild with cmd
|
139
|
-
::Kernel.exec(cmd)
|
140
|
+
::Kernel.exec(*Shellwords.shellwords(cmd))
|
140
141
|
}
|
141
142
|
|
142
143
|
# we do not use these ends of the pipes in the child
|
@@ -177,7 +178,7 @@ module Bluepill
|
|
177
178
|
# TODO: need a mutex here
|
178
179
|
store[:ps_axu] ||= begin
|
179
180
|
# BSD style ps invocation
|
180
|
-
lines = `ps axo pid
|
181
|
+
lines = `ps axo pid,ppid,pcpu,rss`.split("\n")
|
181
182
|
|
182
183
|
lines.inject(Hash.new) do |mem, line|
|
183
184
|
chunks = line.split(/\s+/)
|
data/lib/bluepill/trigger.rb
CHANGED
@@ -30,12 +30,21 @@ module Bluepill
|
|
30
30
|
self.process.dispatch!(event, self.class.name.split("::").last)
|
31
31
|
end
|
32
32
|
|
33
|
+
def deep_copy
|
34
|
+
# TODO: This is a kludge. Ideally, process templates
|
35
|
+
# would be facotries, and not a template object.
|
36
|
+
mutex, @mutex = @mutex, nil
|
37
|
+
clone = Marshal.load(Marshal.dump(self))
|
38
|
+
clone.instance_variable_set("@mutex", Monitor.new)
|
39
|
+
@mutex = mutex
|
40
|
+
clone
|
41
|
+
end
|
42
|
+
|
33
43
|
def schedule_event(event, delay)
|
34
44
|
# TODO: maybe wrap this in a ScheduledEvent class with methods like cancel
|
35
45
|
thread = Thread.new(self) do |trigger|
|
36
46
|
begin
|
37
47
|
sleep delay.to_f
|
38
|
-
trigger.logger.info("Retrying from flapping")
|
39
48
|
trigger.dispatch!(event)
|
40
49
|
trigger.mutex.synchronize do
|
41
50
|
trigger.scheduled_events.delete_if { |_, thread| thread == Thread.current }
|
@@ -57,4 +66,4 @@ module Bluepill
|
|
57
66
|
end
|
58
67
|
|
59
68
|
end
|
60
|
-
end
|
69
|
+
end
|
@@ -43,11 +43,9 @@ module Bluepill
|
|
43
43
|
if duration
|
44
44
|
self.logger.info "Flapping detected: retrying in #{self.retry_in} seconds"
|
45
45
|
|
46
|
-
self.schedule_event(:start, self.retry_in)
|
47
|
-
|
48
|
-
|
49
|
-
self.dispatch!(:unmonitor)
|
50
|
-
|
46
|
+
self.schedule_event(:start, self.retry_in) unless self.retry_in == 0 # retry_in zero means "do not retry, ever"
|
47
|
+
self.schedule_event(:unmonitor, 0)
|
48
|
+
|
51
49
|
@timeline.clear
|
52
50
|
|
53
51
|
# This will prevent a transition from happening in the process state_machine
|
@@ -56,4 +54,4 @@ module Bluepill
|
|
56
54
|
end
|
57
55
|
end
|
58
56
|
end
|
59
|
-
end
|
57
|
+
end
|
data/lib/bluepill/version.rb
CHANGED
data/lib/example.rb
CHANGED
@@ -6,7 +6,7 @@ ROOT_DIR = "/tmp/bp"
|
|
6
6
|
|
7
7
|
# Watch with
|
8
8
|
# watch -n0.2 'ps axu | egrep "(CPU|forking|bluepill|sleep)" | grep -v grep | sort'
|
9
|
-
Bluepill.application(:sample_app
|
9
|
+
Bluepill.application(:sample_app) do |app|
|
10
10
|
0.times do |i|
|
11
11
|
app.process("process_#{i}") do |process|
|
12
12
|
process.pid_file = "#{ROOT_DIR}/pids/process_#{i}.pid"
|
@@ -63,8 +63,8 @@ Bluepill.application(:sample_app, :base_dir => "/tmp/bluepill") do |app|
|
|
63
63
|
|
64
64
|
1.times do |i|
|
65
65
|
app.process("group_process_#{i}") do |process|
|
66
|
-
|
67
|
-
|
66
|
+
process.uid = "rohith"
|
67
|
+
process.gid = "wheel"
|
68
68
|
|
69
69
|
process.stderr = "/tmp/err.log"
|
70
70
|
process.stdout = "/tmp/err.log"
|
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: 69
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 45
|
10
|
+
version: 0.0.45
|
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:
|
20
|
+
date: 2011-03-24 00:00:00 +03:00
|
21
21
|
default_executable: bluepill
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -67,6 +67,14 @@ dependencies:
|
|
67
67
|
- 8
|
68
68
|
- 0
|
69
69
|
version: 0.8.0
|
70
|
+
- - <=
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 51
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
- 9
|
76
|
+
- 4
|
77
|
+
version: 0.9.4
|
70
78
|
type: :runtime
|
71
79
|
version_requirements: *id003
|
72
80
|
- !ruby/object:Gem::Dependency
|