From eeaf6837a013474d4d8531d17921965cb614b652 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sat, 31 Aug 2024 11:35:59 +0100 Subject: [PATCH] Use new rake task to run database cleanups --- cookbooks/web/recipes/cleanup.rb | 33 +++++++++++++++---- .../web/templates/default/cleanup.cron.erb | 3 -- 2 files changed, 26 insertions(+), 10 deletions(-) delete mode 100644 cookbooks/web/templates/default/cleanup.cron.erb diff --git a/cookbooks/web/recipes/cleanup.rb b/cookbooks/web/recipes/cleanup.rb index 9ce886114..c1c47a0c4 100644 --- a/cookbooks/web/recipes/cleanup.rb +++ b/cookbooks/web/recipes/cleanup.rb @@ -19,13 +19,32 @@ include_recipe "web::base" -ruby = "ruby#{node[:ruby][:version]}" +web_passwords = data_bag_item("web", "passwords") + rails_directory = "#{node[:web][:base_directory]}/rails" -template "/etc/cron.daily/web-cleanup" do - source "cleanup.cron.erb" - owner "root" - group "root" - mode "755" - variables :ruby => ruby, :directory => rails_directory +file "/etc/cron.daily/web-cleanup" do + action :delete +end + +systemd_service "rails-cleanup" do + description "Rails cleanup" + type "simple" + environment "RAILS_ENV" => "production", + "SECRET_KEY_BASE" => web_passwords["secret_key_base"] + user "rails" + working_directory rails_directory + exec_start "#{node[:ruby][:bundle]} exec rails db:expire_tokens" + sandbox :enable_network => true + memory_deny_write_execute false + read_write_paths "/var/log/web" +end + +systemd_timer "rails-cleanup" do + description "Rails cleanup" + on_calendar "02:00" +end + +service "rails-cleanup.timer" do + action [:enable, :start] end diff --git a/cookbooks/web/templates/default/cleanup.cron.erb b/cookbooks/web/templates/default/cleanup.cron.erb deleted file mode 100644 index 390b5bcc4..000000000 --- a/cookbooks/web/templates/default/cleanup.cron.erb +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -<%= @ruby %> <%= @directory %>/script/cleanup -- 2.39.5