X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/85b3023748f27b456a308eff4d61d9149efd32d0..e92ed5e09215d67f2bd7dc21a32425d7ec5aa26f:/cookbooks/tile/templates/default/cleanup-tiles.erb?ds=sidebyside diff --git a/cookbooks/tile/templates/default/cleanup-tiles.erb b/cookbooks/tile/templates/default/cleanup-tiles.erb index e58e0bdbf..721660bb1 100644 --- a/cookbooks/tile/templates/default/cleanup-tiles.erb +++ b/cookbooks/tile/templates/default/cleanup-tiles.erb @@ -5,19 +5,26 @@ 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) +if (df($tiledir)->{per} > 88) { - 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", "+2", "-fprintf", $tempfile, "%A@ %p\n"); open(TILES, "-|", "sort", "-n", $tempfile) || die "Can't open $tempfile: $!"; - while (df($tiledir)->{per} > 80 && ! eof(TILES)) + while (df($tiledir)->{per} > 80) { for my $n (1..1000) { @@ -28,13 +35,28 @@ 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 + { + 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;