]> git.openstreetmap.org Git - chef.git/commitdiff
nginx: cleanup historical cache dir
authorGrant Slater <git@firefishy.com>
Tue, 31 Mar 2020 20:47:57 +0000 (21:47 +0100)
committerGrant Slater <git@firefishy.com>
Tue, 31 Mar 2020 20:47:57 +0000 (21:47 +0100)
cookbooks/nginx/recipes/default.rb
cookbooks/nginx/templates/default/nginx-old-cache-cleanup.erb [new file with mode: 0644]
cookbooks/nginx/templates/nginx-old-cache-cleanup.cron.erb [new file with mode: 0644]

index a55dc14bef92ed851f264b3689083ff668ec644e..f17e3dc44de3323de3c0c988a5729a760ff447d5 100644 (file)
@@ -59,3 +59,17 @@ package "libwww-perl"
 
 munin_plugin "nginx_request"
 munin_plugin "nginx_status"
+
+template "/usr/local/bin/nginx-old-cache-cleanup" do
+  source "nginx-old-cache-cleanup.erb"
+  owner "root"
+  group "root"
+  mode 0o755
+end
+
+template "/etc/cron.d/nginx-old-cache-cleanup" do
+  source "nginx-old-cache-cleanup.cron.erb"
+  owner "root"
+  group "root"
+  mode 0o644
+end
diff --git a/cookbooks/nginx/templates/default/nginx-old-cache-cleanup.erb b/cookbooks/nginx/templates/default/nginx-old-cache-cleanup.erb
new file mode 100644 (file)
index 0000000..bb1cf8f
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash
+set -e
+/usr/bin/renice -n 19 $$
+/usr/bin/ionice -c 3 -p $$
+[[ -d "/var/cache/nginx/fastcgi-cache" ]] && /usr/bin/find /var/cache/nginx/fastcgi-cache/?/??/ -maxdepth 1 -type f -delete || true
+[[ -d "/var/cache/nginx/fastcgi-cache" ]] && /usr/bin/find /var/cache/nginx/fastcgi-cache/ -maxdepth 2 -mindepth 2 -type d -wholename '*/?/??' -delete
+[[ -d "/var/cache/nginx/fastcgi-cache" ]] && /usr/bin/find /var/cache/nginx/fastcgi-cache/ -maxdepth 1 -mindepth 1 -type d -wholename '*/?' -delete
+[[ -d "/var/cache/nginx/proxy-cache" ]] && /usr/bin/find /var/cache/nginx/proxy-cache/?/??/ -maxdepth 1 -type f -delete  || true
+[[ -d "/var/cache/nginx/proxy-cache" ]] && /usr/bin/find /var/cache/nginx/proxy-cache/ -maxdepth 2 -mindepth 2 -type d -wholename '*/?/??' -delete
+[[ -d "/var/cache/nginx/proxy-cache" ]] && /usr/bin/find /var/cache/nginx/proxy-cache/ -maxdepth 1 -mindepth 1 -type d -wholename '*/?' -delete
diff --git a/cookbooks/nginx/templates/nginx-old-cache-cleanup.cron.erb b/cookbooks/nginx/templates/nginx-old-cache-cleanup.cron.erb
new file mode 100644 (file)
index 0000000..9f21e45
--- /dev/null
@@ -0,0 +1,2 @@
+# Cleanup old nginx cache storage
+15 23 * * * www-data /usr/bin/timeout 6h /usr/local/bin/nginx-old-cache-cleanup