bluepill 0.0.32 → 0.0.33
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/bluepill +4 -1
- data/bluepill.gemspec +2 -2
- data/lib/bluepill/application.rb +14 -4
- data/lib/bluepill/controller.rb +13 -30
- data/lib/bluepill/socket.rb +14 -2
- data/lib/bluepill/version.rb +1 -1
- data/lib/example.rb +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.33
|
data/bin/bluepill
CHANGED
@@ -55,7 +55,10 @@ APPLICATION_COMMANDS = %w(status start stop restart unmonitor quit log)
|
|
55
55
|
|
56
56
|
controller = Bluepill::Controller.new(options.slice(:base_dir, :log_file))
|
57
57
|
|
58
|
-
if controller.running_applications.include?(
|
58
|
+
if controller.running_applications.include?(File.basename($0)) && File.symlink?($0)
|
59
|
+
# bluepill was called as a symlink with the name of the target application
|
60
|
+
options[:application] = File.basename($0)
|
61
|
+
elsif controller.running_applications.include?(ARGV.first)
|
59
62
|
# the first arg is the application name
|
60
63
|
options[:application] = ARGV.shift
|
61
64
|
elsif APPLICATION_COMMANDS.include?(ARGV.first)
|
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.33"
|
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-02-10}
|
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}
|
data/lib/bluepill/application.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
1
3
|
module Bluepill
|
2
4
|
class Application
|
3
5
|
PROCESS_COMMANDS = [:start, :stop, :restart, :unmonitor, :status]
|
@@ -20,8 +22,14 @@ module Bluepill
|
|
20
22
|
|
21
23
|
self.setup_signal_traps
|
22
24
|
self.setup_pids_dir
|
25
|
+
|
26
|
+
@mutex = Mutex.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def mutex(&b)
|
30
|
+
@mutex.synchronize(&b)
|
23
31
|
end
|
24
|
-
|
32
|
+
|
25
33
|
def load
|
26
34
|
begin
|
27
35
|
self.start_server
|
@@ -79,7 +87,7 @@ module Bluepill
|
|
79
87
|
client = self.socket.accept
|
80
88
|
command, *args = client.readline.strip.split(":")
|
81
89
|
response = begin
|
82
|
-
self.send(command, *args)
|
90
|
+
mutex { self.send(command, *args) }
|
83
91
|
rescue Exception => e
|
84
92
|
e
|
85
93
|
end
|
@@ -116,8 +124,10 @@ module Bluepill
|
|
116
124
|
def run
|
117
125
|
@running = true # set to false by signal trap
|
118
126
|
while @running
|
119
|
-
|
120
|
-
|
127
|
+
mutex do
|
128
|
+
System.reset_data
|
129
|
+
self.groups.each { |_, group| group.tick }
|
130
|
+
end
|
121
131
|
sleep 1
|
122
132
|
end
|
123
133
|
cleanup
|
data/lib/bluepill/controller.rb
CHANGED
@@ -58,30 +58,19 @@ module Bluepill
|
|
58
58
|
|
59
59
|
def send_to_daemon(application, command, *args)
|
60
60
|
begin
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
$stderr.puts "Received error from server:"
|
73
|
-
$stderr.puts response.inspect
|
74
|
-
$stderr.puts response.backtrace.join("\n")
|
75
|
-
exit(8)
|
76
|
-
else
|
77
|
-
response
|
78
|
-
end
|
79
|
-
else
|
80
|
-
abort("No response from server")
|
81
|
-
end
|
61
|
+
verify_version!(application)
|
62
|
+
|
63
|
+
command = ([command, *args]).join(":")
|
64
|
+
response = Socket.client_command(base_dir, application, command)
|
65
|
+
if response.is_a?(Exception)
|
66
|
+
$stderr.puts "Received error from server:"
|
67
|
+
$stderr.puts response.inspect
|
68
|
+
$stderr.puts response.backtrace.join("\n")
|
69
|
+
exit(8)
|
70
|
+
else
|
71
|
+
response
|
82
72
|
end
|
83
|
-
|
84
|
-
abort("Socket Timeout: Server may not be responding")
|
73
|
+
|
85
74
|
rescue Errno::ECONNREFUSED
|
86
75
|
abort("Connection Refused: Server is not running")
|
87
76
|
end
|
@@ -118,13 +107,7 @@ module Bluepill
|
|
118
107
|
|
119
108
|
def verify_version!(application)
|
120
109
|
begin
|
121
|
-
|
122
|
-
socket.puts("version")
|
123
|
-
buffer = ""
|
124
|
-
while line = socket.gets
|
125
|
-
buffer << line
|
126
|
-
end
|
127
|
-
version = Marshal.load(buffer)
|
110
|
+
version = Socket.client_command(base_dir, application, "version")
|
128
111
|
if version != Bluepill::VERSION
|
129
112
|
abort("The running version of your daemon seems to be out of date.\nDaemon Version: #{version}, CLI Version: #{Bluepill::VERSION}")
|
130
113
|
end
|
data/lib/bluepill/socket.rb
CHANGED
@@ -3,10 +3,22 @@ require 'socket'
|
|
3
3
|
module Bluepill
|
4
4
|
module Socket
|
5
5
|
TIMEOUT = 10
|
6
|
+
|
6
7
|
extend self
|
7
8
|
|
8
|
-
def client(base_dir, name)
|
9
|
-
UNIXSocket.open(socket_path(base_dir, name))
|
9
|
+
def client(base_dir, name, &b)
|
10
|
+
UNIXSocket.open(socket_path(base_dir, name), &b)
|
11
|
+
end
|
12
|
+
|
13
|
+
def client_command(base_dir, name, command)
|
14
|
+
client(base_dir, name) do |socket|
|
15
|
+
Timeout.timeout(TIMEOUT) do
|
16
|
+
socket.puts command
|
17
|
+
Marshal.load(socket)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
rescue EOFError, Timeout::Error
|
21
|
+
abort("Socket Timeout: Server may not be responding")
|
10
22
|
end
|
11
23
|
|
12
24
|
def server(base_dir, name)
|
data/lib/bluepill/version.rb
CHANGED
data/lib/example.rb
CHANGED
@@ -80,11 +80,11 @@ Bluepill.application(:sample_app) do |app|
|
|
80
80
|
|
81
81
|
# process.group = "grouped"
|
82
82
|
|
83
|
-
process.start_command = "
|
83
|
+
process.start_command = "ruby /tmp/foo.rb"
|
84
84
|
process.stop_command = "kill {{PID}}"
|
85
85
|
process.daemonize = true
|
86
86
|
process.pid_file = "/tmp/process_#{i}.pid"
|
87
|
-
|
87
|
+
process.working_dir = "/tmp"
|
88
88
|
process.checks :always_false, :every => 1, :times => [20,21]
|
89
89
|
process.checks :flapping, :times => 200, :within => 900.seconds, :retry_in => 7.seconds
|
90
90
|
process.checks :mem_usage, :every => 1, :below => 300.megabytes, :times => [3,5]
|
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.33
|
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: 2010-
|
14
|
+
date: 2010-02-10 00:00:00 -08:00
|
15
15
|
default_executable: bluepill
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|