[Jifty-commit] r5215 - in jifty/trunk: lib/Jifty/Plugin

Jifty commits jifty-commit at lists.jifty.org
Wed Mar 12 16:16:16 EDT 2008


Author: alexmv
Date: Wed Mar 12 16:16:14 2008
New Revision: 5215

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Plugin/Monitoring.pm

Log:
 r28459 at kohr-ah:  chmrr | 2008-03-12 16:16:09 -0400
  * Check validity of PID in the lock file


Modified: jifty/trunk/lib/Jifty/Plugin/Monitoring.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Monitoring.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/Monitoring.pm	Wed Mar 12 16:16:14 2008
@@ -323,9 +323,26 @@
     $self->current_monitor(undef);
 }
 
+=head2 lock
+
+Attempt to determine if there are other monitoring processes running.
+If there are, we return false.  This keeps a long-running monitor from
+making later jobs pile up.
+
+=cut
+
 sub lock {
     my $self = shift;
-    return if -e $self->lockfile;
+    if (-e $self->lockfile) {
+        my ($pid) = do {local @ARGV = ($self->lockfile); <>};
+        if (kill 0, $pid) {
+            Jifty->log->warn("Monitor PID $pid still running");
+            return 0;
+        } else {
+            Jifty->log->warn("Stale PID file @{[$self->lockfile]}; removing");
+            unlink($self->lockfile);
+        }
+    }
     unless (open PID, ">", $self->lockfile) {
         Jifty->log->warn("Can't open lockfile @{[$self->lockfile]}: $!");
         return 0;
@@ -336,6 +353,12 @@
     return 1;
 }
 
+=head2 DESTROY
+
+On destruction, remove the lockfile.
+
+=cut
+
 sub DESTROY {
     my $self = shift;
     unlink $self->lockfile if $self->has_lock;


More information about the Jifty-commit mailing list