]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/tile/templates/default/cleanup-tiles.erb
Ignore lost+found when cleaning up tiles
[chef.git] / cookbooks / tile / templates / default / cleanup-tiles.erb
index 31a7fadd99c43c212ef84b1889462bd9e86b96f3..3cbd64b34b17ea720e657fe59ed1586c822485b0 100644 (file)
@@ -7,13 +7,19 @@ use warnings;
 
 use File::Temp qw(tmpnam);
 use Filesys::Df;
+use LockFile::Simple;
 
 my $tiledir = shift @ARGV;
+
+my $lockmgr = LockFile::Simple->make(-autoclean => 1, -max => 1, -hold => 0, -warn => 0);
+
+$lockmgr->lock("${tiledir}/cleanup") || exit 0;
+
 my $tempfile = tmpnam();
 
 if (df($tiledir)->{per} > 90)
 {
-    system("find", $tiledir, "-xdev", "-type", "f", "-name", "*.meta", "-atime", "+60", "-fprintf", $tempfile, "%A@ %p\n");
+    system("find", $tiledir, "-name", "lost+found", "-prune", "-o", "-xdev", "-type", "f", "-name", "*.meta", "-atime", "+28", "-fprintf", $tempfile, "%A@ %p\n");
 
     open(TILES, "-|", "sort", "-n", $tempfile) || die "Can't open $tempfile: $!";
 
@@ -29,12 +35,22 @@ if (df($tiledir)->{per} > 90)
 
                 unlink($tile) || warn "Can't remove $tile: $!";
             }
+            else
+            {
+                goto done;
+            }
         }
     }
 
+  done:
+
     close(TILES);
+
+    warn "Tile expiry finished before threshold reached" if df($tiledir)->{per} > 80;
 }
 
 unlink($tempfile);
 
+$lockmgr->unlock("${tiledir}/cleanup");
+
 exit 0;