From 5c2f951094034496e684f32aced35f1b089b59bf Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 4 Dec 2022 22:39:40 +0000 Subject: [PATCH] Use a systemd timer to cleanup stale export files --- cookbooks/systemd/resources/service.rb | 1 + .../systemd/templates/default/service.erb | 3 +++ cookbooks/tile/recipes/default.rb | 25 +++++++++++++++---- .../tile/templates/default/export.cron.erb | 6 ----- 4 files changed, 24 insertions(+), 11 deletions(-) delete mode 100644 cookbooks/tile/templates/default/export.cron.erb diff --git a/cookbooks/systemd/resources/service.rb b/cookbooks/systemd/resources/service.rb index 662528c2b..1194d4fd6 100644 --- a/cookbooks/systemd/resources/service.rb +++ b/cookbooks/systemd/resources/service.rb @@ -29,6 +29,7 @@ property :condition_path_exists_glob, [String, Array] property :after, [String, Array] property :conflicts, [String, Array] property :wants, [String, Array] +property :joins_namespace_of, [String, Array] property :type, String, :is => %w[simple forking oneshot dbus notify idle] property :limit_nofile, Integer property :limit_as, [Integer, String] diff --git a/cookbooks/systemd/templates/default/service.erb b/cookbooks/systemd/templates/default/service.erb index 1f11ffbf6..858dbb327 100644 --- a/cookbooks/systemd/templates/default/service.erb +++ b/cookbooks/systemd/templates/default/service.erb @@ -19,6 +19,9 @@ Conflicts=<%= Array(@conflicts).join(" ") %> <% if @wants -%> Wants=<%= Array(@wants).join(" ") %> <% end -%> +<% if @joins_namespace_of -%> +JoinsNamespaceOf=<%= Array(@joins_namespace_of).join(" ") %> +<% end -%> [Service] <% if @type -%> diff --git a/cookbooks/tile/recipes/default.rb b/cookbooks/tile/recipes/default.rb index a9b503c1c..9d1be8020 100644 --- a/cookbooks/tile/recipes/default.rb +++ b/cookbooks/tile/recipes/default.rb @@ -187,11 +187,26 @@ template "/srv/tile.openstreetmap.org/cgi-bin/debug" do mode "755" end -template "/etc/cron.hourly/export" do - source "export.cron.erb" - owner "root" - group "root" - mode "755" +systemd_service "export-cleanup" do + description "Cleanup stale export temporary files" + joins_namespace_of "apache2.service" + exec_start "find /tmp -ignore_readdir_race -name 'export??????' -mmin +60 -delete" + user "www-data" + sandbox true +end + +systemd_timer "export-cleanup" do + description "Cleanup stale export temporary files" + on_boot_sec "60m" + on_unit_inactive_sec "60m" +end + +service "export-cleanup.timer" do + action [:enable, :start] +end + +file "/etc/cron.hourly/export" do + action :delete end directory "/srv/tile.openstreetmap.org/data" do diff --git a/cookbooks/tile/templates/default/export.cron.erb b/cookbooks/tile/templates/default/export.cron.erb deleted file mode 100644 index b598e4113..000000000 --- a/cookbooks/tile/templates/default/export.cron.erb +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -# DO NOT EDIT - This file is being maintained by Chef - -# Removes stale tmp files from the export tab -exec find /tmp -ignore_readdir_race -name 'export??????' -mmin +60 -delete -- 2.39.5