From e1eee7937a3b5f480697025d783104f0a5711eb2 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 4 Oct 2013 20:16:14 +0100 Subject: [PATCH] Use a lock file to stop multiple tile expirys running at once --- cookbooks/tile/recipes/default.rb | 1 + cookbooks/tile/templates/default/cleanup-tiles.erb | 6 ++++++ 2 files changed, 7 insertions(+) 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; -- 2.39.5