]> git.openstreetmap.org Git - chef.git/commitdiff
Add cleanup job for replication logs
authorTom Hughes <tom@compton.nu>
Thu, 18 Nov 2021 18:55:57 +0000 (18:55 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 18 Nov 2021 18:57:34 +0000 (18:57 +0000)
cookbooks/planet/recipes/replication.rb
cookbooks/planet/templates/default/replicate-cleanup.erb [new file with mode: 0644]

index d25197171412538e41ef77475d5a96429f2b20b5..b59e0bf0c8b437a98369a2679981f3b3776e27de 100644 (file)
@@ -81,6 +81,13 @@ template "/usr/local/bin/replicate-minute" do
   mode "755"
 end
 
+template "/usr/local/bin/replicate-cleanup" do
+  source "replicate-cleanup.erb"
+  owner "root"
+  group "root"
+  mode "755"
+end
+
 template "/usr/local/bin/users-agreed" do
   source "users-agreed.erb"
   owner "root"
@@ -325,6 +332,27 @@ systemd_timer "replication-daily" do
   on_calendar "*-*-* *:02/15:00"
 end
 
+## Replication cleanup
+
+systemd_service "replication-cleanup" do
+  description "Cleanup replication"
+  user "planet"
+  exec_start "/usr/local/bin/replicate-cleanup"
+  private_tmp true
+  private_devices true
+  private_network true
+  protect_system "full"
+  protect_home true
+  no_new_privileges true
+end
+
+systemd_timer "replication-cleanup" do
+  description "Cleanup replication"
+  on_boot_sec 60
+  on_unit_active_sec 86400
+  accuracy_sec 1800
+end
+
 ## Enable/disable feeds
 
 if node[:planet][:replication] == "enabled"
@@ -361,6 +389,10 @@ if node[:planet][:replication] == "enabled"
   service "replication-daily.timer" do
     action [:enable, :start]
   end
+
+  service "replication-cleanup.timer" do
+    action [:enable, :start]
+  end
 else
   cron_d "users-agreed" do
     action :delete
@@ -385,4 +417,8 @@ else
   service "replication-daily.timer" do
     action [:stop, :disable]
   end
+
+  service "replication-cleanup.timer" do
+    action [:stop, :disable]
+  end
 end
diff --git a/cookbooks/planet/templates/default/replicate-cleanup.erb b/cookbooks/planet/templates/default/replicate-cleanup.erb
new file mode 100644 (file)
index 0000000..6049cc3
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+set -e
+
+find /var/lib/replication/minute -name *.done -mtime +14 -print0 | xargs -0r rm