X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/e1eee7937a3b5f480697025d783104f0a5711eb2..891a36508c7c3bbfe041cb0dd1a39c2f84d0f9ff:/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 9209a2644..721660bb1 100644 --- a/cookbooks/tile/templates/default/cleanup-tiles.erb +++ b/cookbooks/tile/templates/default/cleanup-tiles.erb @@ -5,19 +5,22 @@ use strict; use warnings; +use File::Basename; use File::Temp qw(tmpnam); use Filesys::Df; -use LockFile::Simple qw(lock unlock); +use LockFile::Simple; my $tiledir = shift @ARGV; -lock($tiledir) || exit 0; +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", "+35", "-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: $!"; @@ -32,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 { @@ -49,6 +57,6 @@ if (df($tiledir)->{per} > 90) unlink($tempfile); -unlock($tiledir); +$lockmgr->unlock("${tiledir}/cleanup"); exit 0;