]> git.openstreetmap.org Git - chef.git/blob - cookbooks/tile/templates/default/cleanup-tiles.erb
Don't warn when the tile cleanup script can't get a lock
[chef.git] / cookbooks / tile / templates / default / cleanup-tiles.erb
1 #!/usr/bin/perl
2
3 # DO NOT EDIT - This file is being maintained by Chef
4
5 use strict;
6 use warnings;
7
8 use File::Temp qw(tmpnam);
9 use Filesys::Df;
10 use LockFile::Simple;
11
12 my $tiledir = shift @ARGV;
13
14 my $lockmgr = LockFile::Simple->make(-autoclean => 1, -max => 0, -warn => 0);
15
16 $lockmgr->lock($tiledir) || exit 0;
17
18 my $tempfile = tmpnam();
19
20 if (df($tiledir)->{per} > 90)
21 {
22     system("find", $tiledir, "-xdev", "-type", "f", "-name", "*.meta", "-atime", "+35", "-fprintf", $tempfile, "%A@ %p\n");
23
24     open(TILES, "-|", "sort", "-n", $tempfile) || die "Can't open $tempfile: $!";
25
26     while (df($tiledir)->{per} > 80)
27     {
28         for my $n (1..1000)
29         {
30             if (defined(my $line = readline(TILES)))
31             {
32                 chomp $line;
33
34                 my($time,$tile) = split(/ /, $line);
35
36                 unlink($tile) || warn "Can't remove $tile: $!";
37             }
38             else
39             {
40                 goto done;
41             }
42         }
43     }
44
45   done:
46
47     close(TILES);
48
49     warn "Tile expiry finished before threshold reached" if df($tiledir)->{per} > 80;
50 }
51
52 unlink($tempfile);
53
54 $lockmgr->unlock($tiledir);
55
56 exit 0;