<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -26,8 +26,20 @@ controller = Bluepill::Controller.new(options.slice(:base_dir))
 
 if controller.list.include?(ARGV.first)
   options[:application] = ARGV.shift 
-elsif controller.list.length == 1 &amp;&amp; ALLOWED_COMMANDS.include?(ARGV.first)
-  options[:application] = controller.list.first
+elsif ALLOWED_COMMANDS.include?(ARGV.first)
+  if controller.list.length == 1
+    options[:application] = controller.list.first
+  elsif controller.list.length &gt; 1
+    $stderr.puts &quot;You must specify an application name. Here's the list:&quot;
+    controller.list.each_with_index do |app, index|
+      $stderr.puts &quot;  #{index + 1}. #{app}&quot;
+    end
+    $stderr.puts &quot;Usage: bluepill [app] cmd [options]&quot;
+    exit
+  else
+    $stderr.puts &quot;There are no running bluepill daemons.\nTo start a bluepill daemon, use: bluepill load &lt;config file&gt;&quot;
+    exit
+  end
 end
 
 options[:command] = ARGV.shift</diff>
      <filename>bin/bluepill</filename>
    </modified>
    <modified>
      <diff>@@ -11,12 +11,25 @@ module Bluepill
       self.pids_dir = File.join(base_dir, 'pids')
       self.applications = Hash.new 
       setup_dir_structure
+      cleanup
     end
     
     def list
       Dir[File.join(sockets_dir, &quot;*.sock&quot;)].map{|x| File.basename(x, &quot;.sock&quot;)}
     end
     
+    def cleanup
+      self.list.each do |app|
+        pid = pid_for(app)
+        if !pid || !alive?(pid)
+          pid_file = File.join(self.pids_dir, &quot;#{app}.pid&quot;)
+          sock_file = File.join(self.sockets_dir, &quot;#{app}.sock&quot;)
+          File.unlink(pid_file) if File.exists?(pid_file)
+          File.unlink(sock_file) if File.exists?(sock_file)
+        end
+      end
+    end
+    
     def send_cmd(application, command, *args)
       applications[application] ||= Application.new(application, {:base_dir =&gt; base_dir})
       applications[application].send(command.to_sym, *args.compact)
@@ -24,6 +37,21 @@ module Bluepill
     
     private
     
+    def pid_for(app)
+      pid_file = File.join(self.pids_dir, &quot;#{app}.pid&quot;)
+      File.exists?(pid_file) &amp;&amp; File.read(pid_file).to_i
+    end
+    
+    
+    def alive?(pid)
+      begin
+        ::Process.kill(0, pid)
+        true
+      rescue Errno::ESRCH
+        false
+      end
+    end
+    
     def setup_dir_structure
       [@sockets_dir, @pids_dir].each do |dir|
         FileUtils.mkdir_p(dir) unless File.exists?(dir)</diff>
      <filename>lib/bluepill/controller.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>13ade3093affd8589d7317b34dadda915a9c9f71</id>
    </parent>
  </parents>
  <author>
    <name>Arya Asemanfar</name>
    <email>arya.asemanfar@gmail.com</email>
  </author>
  <url>http://github.com/arya/bluepill/commit/3d833ed80ddb32a750270c969f60bcfcb1af0132</url>
  <id>3d833ed80ddb32a750270c969f60bcfcb1af0132</id>
  <committed-date>2009-11-06T10:12:18-08:00</committed-date>
  <authored-date>2009-11-06T10:12:18-08:00</authored-date>
  <message>error message for when you need to specify a sock file or there are no sock files</message>
  <tree>9772cbd323d122d5a1721924fccab4d60bd16b94</tree>
  <committer>
    <name>Arya Asemanfar</name>
    <email>arya.asemanfar@gmail.com</email>
  </committer>
</commit>
