From: Tom Hughes Date: Fri, 4 Oct 2013 19:16:14 +0000 (+0100) Subject: Use a lock file to stop multiple tile expirys running at once X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/e1eee7937a3b5f480697025d783104f0a5711eb2 Use a lock file to stop multiple tile expirys running at once --- diff --git a/cookbooks/tile/recipes/default.rb b/cookbooks/tile/recipes/default.rb index d2f875611..b80dc01fb 100644 --- a/cookbooks/tile/recipes/default.rb +++ b/cookbooks/tile/recipes/default.rb @@ -488,6 +488,7 @@ template "/etc/rsyslog.d/20-renderd.conf" do notifies :restart, "service[rsyslog]" end +package "liblockfile-simple-perl" package "libfilesys-df-perl" template "/usr/local/bin/cleanup-tiles" do diff --git a/cookbooks/tile/templates/default/cleanup-tiles.erb b/cookbooks/tile/templates/default/cleanup-tiles.erb index c4bff4cce..9209a2644 100644 --- a/cookbooks/tile/templates/default/cleanup-tiles.erb +++ b/cookbooks/tile/templates/default/cleanup-tiles.erb @@ -7,8 +7,12 @@ use warnings; use File::Temp qw(tmpnam); use Filesys::Df; +use LockFile::Simple qw(lock unlock); my $tiledir = shift @ARGV; + +lock($tiledir) || exit 0; + my $tempfile = tmpnam(); if (df($tiledir)->{per} > 90) @@ -45,4 +49,6 @@ if (df($tiledir)->{per} > 90) unlink($tempfile); +unlock($tiledir); + exit 0;