bluepill 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/bluepill +15 -11
- data/bluepill.gemspec +1 -1
- data/lib/bluepill/controller.rb +9 -10
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.18
|
data/bin/bluepill
CHANGED
@@ -20,18 +20,19 @@ OptionParser.new do |opts|
|
|
20
20
|
end
|
21
21
|
end.parse!
|
22
22
|
|
23
|
-
APPLICATION_COMMANDS = %w(status start stop restart unmonitor quit)
|
23
|
+
APPLICATION_COMMANDS = %w(status start stop restart unmonitor quit log)
|
24
24
|
|
25
25
|
controller = Bluepill::Controller.new(options.slice(:base_dir))
|
26
26
|
|
27
|
-
if controller.
|
27
|
+
if controller.running_applications.include?(ARGV.first)
|
28
|
+
# the first arg is the application name
|
28
29
|
options[:application] = ARGV.shift
|
29
30
|
elsif APPLICATION_COMMANDS.include?(ARGV.first)
|
30
|
-
if controller.
|
31
|
-
options[:application] = controller.
|
32
|
-
elsif controller.
|
33
|
-
$stderr.puts "You must specify an application name. Here's the list:"
|
34
|
-
controller.
|
31
|
+
if controller.running_applications.length == 1
|
32
|
+
options[:application] = controller.running_applications.first
|
33
|
+
elsif controller.running_applications.length > 1
|
34
|
+
$stderr.puts "You must specify an application name. Here's the list of running applications:"
|
35
|
+
controller.running_applications.each_with_index do |app, index|
|
35
36
|
$stderr.puts " #{index + 1}. #{app}"
|
36
37
|
end
|
37
38
|
$stderr.puts "Usage: bluepill [app] cmd [options]"
|
@@ -47,20 +48,23 @@ options[:command] = ARGV.shift
|
|
47
48
|
case options[:command]
|
48
49
|
when "load"
|
49
50
|
file = ARGV.shift
|
50
|
-
|
51
|
-
|
51
|
+
if File.exists?(file)
|
52
|
+
eval(File.read(file))
|
53
|
+
else
|
54
|
+
$stderr.puts "Can't find file: #{file}"
|
55
|
+
end
|
52
56
|
when "log"
|
53
57
|
orig_pattern = pattern = ARGV.shift
|
54
58
|
pattern = controller.send_cmd(options[:application], :grep_pattern, pattern)
|
55
59
|
|
56
60
|
cmd = "tail -n 100 -f #{options[:log_file]} | grep -E '#{pattern}'"
|
57
|
-
|
61
|
+
puts "Tailing log for #{orig_pattern}..."
|
58
62
|
Kernel.exec(cmd)
|
59
63
|
|
60
64
|
when *APPLICATION_COMMANDS
|
61
65
|
process_or_group_name = ARGV.shift
|
62
66
|
puts controller.send_cmd(options[:application], options[:command], process_or_group_name)
|
63
|
-
|
67
|
+
|
64
68
|
else
|
65
69
|
puts "Unknown command `%s` (or application `%s` has not been loaded yet)" % [options[:command], options[:command]]
|
66
70
|
end
|
data/bluepill.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
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.18"
|
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"]
|
data/lib/bluepill/controller.rb
CHANGED
@@ -14,12 +14,19 @@ module Bluepill
|
|
14
14
|
cleanup
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def running_applications
|
18
18
|
Dir[File.join(sockets_dir, "*.sock")].map{|x| File.basename(x, ".sock")}
|
19
19
|
end
|
20
20
|
|
21
|
+
def send_cmd(application, command, *args)
|
22
|
+
applications[application] ||= Application.new(application, {:base_dir => base_dir})
|
23
|
+
applications[application].send(command.to_sym, *args.compact)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
21
28
|
def cleanup
|
22
|
-
self.
|
29
|
+
self.running_applications.each do |app|
|
23
30
|
pid = pid_for(app)
|
24
31
|
if !pid || !alive?(pid)
|
25
32
|
pid_file = File.join(self.pids_dir, "#{app}.pid")
|
@@ -30,19 +37,11 @@ module Bluepill
|
|
30
37
|
end
|
31
38
|
end
|
32
39
|
|
33
|
-
def send_cmd(application, command, *args)
|
34
|
-
applications[application] ||= Application.new(application, {:base_dir => base_dir})
|
35
|
-
applications[application].send(command.to_sym, *args.compact)
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
40
|
def pid_for(app)
|
41
41
|
pid_file = File.join(self.pids_dir, "#{app}.pid")
|
42
42
|
File.exists?(pid_file) && File.read(pid_file).to_i
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
45
|
def alive?(pid)
|
47
46
|
begin
|
48
47
|
::Process.kill(0, pid)
|