bluepill 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.13
1
+ 0.0.14
data/bin/bluepill CHANGED
@@ -26,8 +26,20 @@ controller = Bluepill::Controller.new(options.slice(:base_dir))
26
26
 
27
27
  if controller.list.include?(ARGV.first)
28
28
  options[:application] = ARGV.shift
29
- elsif controller.list.length == 1 && ALLOWED_COMMANDS.include?(ARGV.first)
30
- options[:application] = controller.list.first
29
+ elsif ALLOWED_COMMANDS.include?(ARGV.first)
30
+ if controller.list.length == 1
31
+ options[:application] = controller.list.first
32
+ elsif controller.list.length > 1
33
+ $stderr.puts "You must specify an application name. Here's the list:"
34
+ controller.list.each_with_index do |app, index|
35
+ $stderr.puts " #{index + 1}. #{app}"
36
+ end
37
+ $stderr.puts "Usage: bluepill [app] cmd [options]"
38
+ exit
39
+ else
40
+ $stderr.puts "There are no running bluepill daemons.\nTo start a bluepill daemon, use: bluepill load <config file>"
41
+ exit
42
+ end
31
43
  end
32
44
 
33
45
  options[:command] = ARGV.shift
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.13"
8
+ s.version = "0.0.14"
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-05}
12
+ s.date = %q{2009-11-06}
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}
@@ -11,12 +11,25 @@ module Bluepill
11
11
  self.pids_dir = File.join(base_dir, 'pids')
12
12
  self.applications = Hash.new
13
13
  setup_dir_structure
14
+ cleanup
14
15
  end
15
16
 
16
17
  def list
17
18
  Dir[File.join(sockets_dir, "*.sock")].map{|x| File.basename(x, ".sock")}
18
19
  end
19
20
 
21
+ def cleanup
22
+ self.list.each do |app|
23
+ pid = pid_for(app)
24
+ if !pid || !alive?(pid)
25
+ pid_file = File.join(self.pids_dir, "#{app}.pid")
26
+ sock_file = File.join(self.sockets_dir, "#{app}.sock")
27
+ File.unlink(pid_file) if File.exists?(pid_file)
28
+ File.unlink(sock_file) if File.exists?(sock_file)
29
+ end
30
+ end
31
+ end
32
+
20
33
  def send_cmd(application, command, *args)
21
34
  applications[application] ||= Application.new(application, {:base_dir => base_dir})
22
35
  applications[application].send(command.to_sym, *args.compact)
@@ -24,6 +37,21 @@ module Bluepill
24
37
 
25
38
  private
26
39
 
40
+ def pid_for(app)
41
+ pid_file = File.join(self.pids_dir, "#{app}.pid")
42
+ File.exists?(pid_file) && File.read(pid_file).to_i
43
+ end
44
+
45
+
46
+ def alive?(pid)
47
+ begin
48
+ ::Process.kill(0, pid)
49
+ true
50
+ rescue Errno::ESRCH
51
+ false
52
+ end
53
+ end
54
+
27
55
  def setup_dir_structure
28
56
  [@sockets_dir, @pids_dir].each do |dir|
29
57
  FileUtils.mkdir_p(dir) unless File.exists?(dir)
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.13
4
+ version: 0.0.14
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-05 00:00:00 -08:00
14
+ date: 2009-11-06 00:00:00 -08:00
15
15
  default_executable: bluepill
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency