X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/31a4c95a00ffaf0a31dea1fafd24072e2268c2a5..a0858c90b268bfa28bc362d687f89e43b48830e3:/cookbooks/tile/templates/default/cleanup-tiles.erb diff --git a/cookbooks/tile/templates/default/cleanup-tiles.erb b/cookbooks/tile/templates/default/cleanup-tiles.erb index 73baaffd9..fa69ef4d9 100644 --- a/cookbooks/tile/templates/default/cleanup-tiles.erb +++ b/cookbooks/tile/templates/default/cleanup-tiles.erb @@ -5,15 +5,22 @@ use strict; use warnings; +use File::Basename; 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, -stale => 1); + +$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, "-xdev", "-name", "lost+found", "-prune", "-o", "-type", "f", "-name", "*.meta", "-atime", "+10", "-fprintf", $tempfile, "%A@ %p\n"); open(TILES, "-|", "sort", "-n", $tempfile) || die "Can't open $tempfile: $!"; @@ -28,6 +35,11 @@ if (df($tiledir)->{per} > 90) my($time,$tile) = split(/ /, $line); unlink($tile) || warn "Can't remove $tile: $!"; + + for (my $dir = dirname($tile); $dir ne $tiledir; $dir = dirname($dir)) + { + rmdir($dir); + } } else { @@ -39,10 +51,12 @@ if (df($tiledir)->{per} > 90) done: close(TILES); + + warn "Tile expiry finished before threshold reached" if df($tiledir)->{per} > 80; } unlink($tempfile); -warn "Tile expiry finished before threshold reached" if df($tiledir)->{per} > 80; +$lockmgr->unlock("${tiledir}/cleanup"); exit 0;