]> git.cworth.org Git - sup/commitdiff
bugfix: lock file now actually periodically touched; also some minor text and code...
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Wed, 6 Jun 2007 00:00:05 +0000 (00:00 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Wed, 6 Jun 2007 00:00:05 +0000 (00:00 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@438 5c8cc53c-5e98-4d25-b20a-d8db53a31250

bin/sup
lib/sup/index.rb
lib/sup/util.rb

diff --git a/bin/sup b/bin/sup
index d16ae802796eeff3777d02d3325b9fca57491fb1..c7d320737eb60e4efb6cc48c6ee4429d1d68182e 100644 (file)
--- a/bin/sup
+++ b/bin/sup
@@ -65,7 +65,7 @@ rescue Index::LockError => e
   h.wrap_at = :auto
   h.say Index.fancy_lock_error_message_for(e)
 
-  case h.ask("Should I ask that the process kill itself? ")
+  case h.ask("Should I ask that process to kill itself? ")
   when /^\s*y\s*$/i
     h.say "Ok, suggesting sepuku..."
     FileUtils.touch Redwood::SUICIDE_FN
index fe7297d3d88a2696dfaaaf68de13916921e520ff..7d1e7a5fc9242e32e971802ce681d2fc85aca2a8 100644 (file)
@@ -29,7 +29,7 @@ class Index
     @analyzer[:body] = sa
     @analyzer[:subject] = sa
     @qparser ||= Ferret::QueryParser.new :default_field => :body, :analyzer => @analyzer
-    @lock = Lockfile.new lockfile, :retries => 0
+    @lock = Lockfile.new lockfile, :retries => 0, :max_age => nil
 
     self.class.i_am_the_instance self
   end
@@ -47,21 +47,27 @@ class Index
 
   def start_lock_update_thread
     Redwood::reporting_thread do
-      sleep 30
-      @lock.touch_yourself
+      while true
+        sleep 30
+        @lock.touch_yourself
+      end
     end
   end
 
   def fancy_lock_error_message_for e
-    mins = (Time.now - e.mtime).to_i / 60
+    secs = Time.now - e.mtime
+    mins = secs.to_i / 60
+    time =
+      if mins == 0
+        "#{secs.to_i} seconds"
+      else
+        "#{mins} minutes"
+      end
 
     <<EOS
 Error: the sup index is locked by another process! User '#{e.user}' on
-host '#{e.host}' is running #{e.pname} with pid #{e.pid} (at least, as of #{mins}
-minutes ago).
-
-Wait for the process to finish, or, if the lockfile is stale, delete it
-manually.
+host '#{e.host}' is running #{e.pname} with pid #{e.pid}. The process was alive
+as of #{time} ago.
 EOS
   end
 
@@ -70,6 +76,11 @@ EOS
       lock
     rescue LockError => e
       $stderr.puts fancy_lock_error_message_for(e)
+      $stderr.puts <<EOS
+
+You can wait for the process to finish, or, if it crashed and left a
+stale lock file behind, you can manually delete #{@lock.path}.
+EOS
       exit
     end
   end
index 582e26f0786f07bb8df43e708aded46037dcf178..8f6680e6eeaa58a065f38d6b7b7e6c6a439defef 100644 (file)
@@ -20,13 +20,11 @@ class Lockfile
 
   def lockinfo_on_disk
     h = load_lock_id IO.read(path)
-    h['mtime'] = File.stat(path).mtime
+    h['mtime'] = File.mtime path
     h
   end
 
-  def touch_yourself
-    touch path
-  end
+  def touch_yourself; touch path end
 end
 
 class Range