bluepill 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/bluepill +0 -5
- data/bluepill.gemspec +6 -5
- data/lib/bluepill/controller.rb +4 -0
- data/lib/bluepill/process.rb +40 -19
- data/lib/bluepill/system.rb +34 -3
- data/lib/example.rb +8 -4
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.20
|
data/bin/bluepill
CHANGED
@@ -23,11 +23,6 @@ end.parse!
|
|
23
23
|
|
24
24
|
APPLICATION_COMMANDS = %w(status start stop restart unmonitor quit log)
|
25
25
|
|
26
|
-
unless File.writable?(options[:base_dir])
|
27
|
-
$stderr.puts "Error: You don't have permissions to #{options[:base_dir]}\nYou should run bluepill as root."
|
28
|
-
exit(3)
|
29
|
-
end
|
30
|
-
|
31
26
|
controller = Bluepill::Controller.new(options.slice(:base_dir))
|
32
27
|
|
33
28
|
if controller.running_applications.include?(ARGV.first)
|
data/bluepill.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
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.20"
|
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{2009-11-
|
12
|
+
s.date = %q{2009-11-15}
|
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}
|
@@ -56,7 +56,7 @@ Gem::Specification.new do |s|
|
|
56
56
|
s.homepage = %q{http://github.com/arya/bluepill}
|
57
57
|
s.rdoc_options = ["--charset=UTF-8"]
|
58
58
|
s.require_paths = ["lib"]
|
59
|
-
s.rubygems_version = %q{1.3.
|
59
|
+
s.rubygems_version = %q{1.3.5}
|
60
60
|
s.summary = %q{A process monitor written in Ruby with stability and minimalism in mind.}
|
61
61
|
s.test_files = [
|
62
62
|
"spec/blue-pill_spec.rb",
|
@@ -89,3 +89,4 @@ Gem::Specification.new do |s|
|
|
89
89
|
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
90
90
|
end
|
91
91
|
end
|
92
|
+
|
data/lib/bluepill/controller.rb
CHANGED
@@ -55,6 +55,10 @@ module Bluepill
|
|
55
55
|
[@sockets_dir, @pids_dir].each do |dir|
|
56
56
|
FileUtils.mkdir_p(dir) unless File.exists?(dir)
|
57
57
|
end
|
58
|
+
|
59
|
+
rescue Errno::EACCES
|
60
|
+
$stderr.puts "Error: You don't have permissions to #{base_dir}\nYou should run bluepill as root."
|
61
|
+
exit(3)
|
58
62
|
end
|
59
63
|
end
|
60
64
|
end
|
data/lib/bluepill/process.rb
CHANGED
@@ -231,16 +231,17 @@ module Bluepill
|
|
231
231
|
logger.warning "Executing start command: #{start_command}"
|
232
232
|
|
233
233
|
if self.daemonize?
|
234
|
-
|
235
|
-
File.open(pid_file, "w") {|f| f.write(child_pid)}
|
234
|
+
System.daemonize(start_command, self.system_command_options)
|
236
235
|
|
237
236
|
else
|
238
237
|
# This is a self-daemonizing process
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
238
|
+
with_timeout(start_grace_time) do
|
239
|
+
result = System.execute_blocking(start_command, self.system_command_options)
|
240
|
+
|
241
|
+
unless result[:exit_code].zero?
|
242
|
+
logger.warning "Start command execution returned non-zero exit code:"
|
243
|
+
logger.warning result.inspect
|
244
|
+
end
|
244
245
|
end
|
245
246
|
end
|
246
247
|
|
@@ -251,13 +252,16 @@ module Bluepill
|
|
251
252
|
if stop_command
|
252
253
|
cmd = process_command(stop_command)
|
253
254
|
logger.warning "Executing stop command: #{cmd}"
|
254
|
-
|
255
|
-
result = System.execute_blocking(cmd, self.system_command_options)
|
256
|
-
unless result[:exit_code].zero?
|
257
|
-
logger.warning "Stop command execution returned non-zero exit code:"
|
258
|
-
logger.warning result.inspect
|
259
|
-
end
|
260
255
|
|
256
|
+
with_timeout(stop_grace_time) do
|
257
|
+
result = System.execute_blocking(cmd, self.system_command_options)
|
258
|
+
|
259
|
+
unless result[:exit_code].zero?
|
260
|
+
logger.warning "Stop command execution returned non-zero exit code:"
|
261
|
+
logger.warning result.inspect
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
261
265
|
else
|
262
266
|
logger.warning "Executing default stop command. Sending TERM signal to #{actual_pid}"
|
263
267
|
signal_process("TERM")
|
@@ -273,11 +277,13 @@ module Bluepill
|
|
273
277
|
|
274
278
|
logger.warning "Executing restart command: #{cmd}"
|
275
279
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
280
|
+
with_timeout(restart_grace_time) do
|
281
|
+
result = System.execute_blocking(cmd, self.system_command_options)
|
282
|
+
|
283
|
+
unless result[:exit_code].zero?
|
284
|
+
logger.warning "Restart command execution returned non-zero exit code:"
|
285
|
+
logger.warning result.inspect
|
286
|
+
end
|
281
287
|
end
|
282
288
|
|
283
289
|
self.skip_ticks_for(restart_grace_time)
|
@@ -374,7 +380,22 @@ module Bluepill
|
|
374
380
|
end
|
375
381
|
|
376
382
|
def system_command_options
|
377
|
-
{
|
383
|
+
{
|
384
|
+
:uid => self.uid,
|
385
|
+
:gid => self.gid,
|
386
|
+
:working_dir => self.working_dir,
|
387
|
+
:pid_file => self.pid_file,
|
388
|
+
:logger => self.logger
|
389
|
+
}
|
390
|
+
end
|
391
|
+
|
392
|
+
def with_timeout(secs, &blk)
|
393
|
+
Timeout.timeout(secs.to_f, &blk)
|
394
|
+
|
395
|
+
rescue Timeout::Error
|
396
|
+
logger.err "Execution is taking longer than expected. Unmonitoring."
|
397
|
+
logger.err "Did you forget to tell bluepill to daemonize this process?"
|
398
|
+
self.dispatch!("unmonitor")
|
378
399
|
end
|
379
400
|
end
|
380
401
|
end
|
data/lib/bluepill/system.rb
CHANGED
@@ -60,15 +60,35 @@ module Bluepill
|
|
60
60
|
rd.close
|
61
61
|
|
62
62
|
drop_privileges(options[:uid], options[:gid])
|
63
|
-
|
63
|
+
|
64
|
+
# if we cannot write the pid file as the provided user, err out
|
65
|
+
exit unless can_write_pid_file(options[:pid_file], options[:logger])
|
66
|
+
|
64
67
|
to_daemonize = lambda do
|
68
|
+
# Setting end PWD env emulates bash behavior when dealing with symlinks
|
65
69
|
Dir.chdir(ENV["PWD"] = options[:working_dir]) if options[:working_dir]
|
66
|
-
|
70
|
+
|
71
|
+
# Forcing execution through bash to make output redirection and shell exapansion in commands work and still have
|
72
|
+
# bluepill monitor the correct process
|
73
|
+
args = ["/bin/sh", "-c", "--", cmd]
|
74
|
+
|
75
|
+
::Kernel.exec(*args)
|
67
76
|
exit
|
68
77
|
end
|
69
78
|
|
70
79
|
daemon_id = Daemonize.call_as_daemon(to_daemonize, nil, cmd)
|
71
|
-
|
80
|
+
|
81
|
+
# Kludge. In order to make bluepill monitor the correct process while given start_commands of the form
|
82
|
+
# "cd /some/dir && ./some/server > /tmp/server.log 2>&1"
|
83
|
+
# we inspect the children of the "sh -c" process and pick it's single child.
|
84
|
+
# There are many cases where this could break. If Bluepill is not monitoring the correct process, try
|
85
|
+
# simplyfying the start_command by moving all the bash scripting to a separate file and specifying that
|
86
|
+
# as the start_command. That said, this should work for 99% use cases.
|
87
|
+
spawned_children = get_children(daemon_id)
|
88
|
+
daemon_id = spawned_children.first if spawned_children.length == 1
|
89
|
+
|
90
|
+
File.open(options[:pid_file], "w") {|f| f.write(daemon_id)}
|
91
|
+
|
72
92
|
wr.write daemon_id
|
73
93
|
wr.close
|
74
94
|
|
@@ -187,5 +207,16 @@ module Bluepill
|
|
187
207
|
::Process::Sys.setgid(gid_num) if gid
|
188
208
|
::Process::Sys.setuid(uid_num) if uid
|
189
209
|
end
|
210
|
+
|
211
|
+
def can_write_pid_file(pid_file, logger)
|
212
|
+
FileUtils.touch(pid_file)
|
213
|
+
File.unlink(pid_file)
|
214
|
+
return true
|
215
|
+
|
216
|
+
rescue Exception => e
|
217
|
+
logger.warning "%s - %s" % [e.class.name, e.message]
|
218
|
+
e.backtrace.each {|l| logger.warning l}
|
219
|
+
return false
|
220
|
+
end
|
190
221
|
end
|
191
222
|
end
|
data/lib/example.rb
CHANGED
@@ -63,11 +63,15 @@ Bluepill.application(:sample_app) do |app|
|
|
63
63
|
|
64
64
|
1.times do |i|
|
65
65
|
app.process("group_process_#{i}") do |process|
|
66
|
-
process.
|
67
|
-
process.
|
68
|
-
|
66
|
+
process.uid = "rohith"
|
67
|
+
process.gid = "wheel"
|
68
|
+
|
69
|
+
process.group = "grouped"
|
70
|
+
process.start_command = %Q{cd /tmp && ruby -e '$stderr.puts("hello stderr");$stdout.puts("hello stdout"); sleep 10' 1>> /tmp/err.log 2>&1 }
|
71
|
+
process.daemonize = false
|
72
|
+
process.pid_file = "/tmp/noperm/p_#{process.group}_#{i}.pid"
|
69
73
|
|
70
|
-
process.checks :always_true, :every =>
|
74
|
+
# process.checks :always_true, :every => 5
|
71
75
|
end
|
72
76
|
end
|
73
77
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bluepill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arya Asemanfar
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2009-11-
|
14
|
+
date: 2009-11-15 00:00:00 -08:00
|
15
15
|
default_executable: bluepill
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
requirements: []
|
132
132
|
|
133
133
|
rubyforge_project:
|
134
|
-
rubygems_version: 1.3.
|
134
|
+
rubygems_version: 1.3.5
|
135
135
|
signing_key:
|
136
136
|
specification_version: 3
|
137
137
|
summary: A process monitor written in Ruby with stability and minimalism in mind.
|