From b01315f998bfc02af57a9ba3ca4100209b47bd46 Mon Sep 17 00:00:00 2001 From: Greg Karekinian Date: Fri, 16 May 2025 18:10:11 +0200 Subject: [PATCH 1/2] Delete old Mastodon media cache every day This is done using a systemd timer Closes #533 --- .../kosmos-mastodon/recipes/default.rb | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/site-cookbooks/kosmos-mastodon/recipes/default.rb b/site-cookbooks/kosmos-mastodon/recipes/default.rb index 7b4dd57..d53ce6a 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/default.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/default.rb @@ -265,6 +265,41 @@ service "mastodon-streaming" do action [:enable, :start] end +# Delete old media cache +systemd_unit 'mastodon-delete-old-media-cache.service' do + content({ + Unit: { + Description: 'Delete old Mastodon media cache' + }, + Service: { + Type: "oneshot", + WorkingDirectory: "#{mastodon_path}", + Environment: "\"RAILS_ENV=#{rails_env}\"", + ExecStart: "#{bundle_path} exec bin/tootctl media remove --days 30", + SyslogIdentifier: "mastodon-delete-old-media-cache" + } + }) + action [:create] +end + +systemd_unit 'mastodon-delete-old-media-cache.timer' do + content({ + Unit: { + Description: 'Delete old Mastodon media cache' + }, + Timer: { + OnCalendar: '*-*-* 00:00:00', + Persistent: 'true' + }, + Install: { + WantedBy: 'timers.target' + } + }) + + triggers_reload true + action [:create, :enable, :start] +end + firewall_rule "mastodon_app" do port node['kosmos-mastodon']['app_port'] source "10.1.1.0/24" From 14687558fea492a02eed1f39d5f44fb6523b6b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Sat, 17 May 2025 10:55:06 +0400 Subject: [PATCH 2/2] Minor cleanup --- site-cookbooks/kosmos-mastodon/recipes/default.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/site-cookbooks/kosmos-mastodon/recipes/default.rb b/site-cookbooks/kosmos-mastodon/recipes/default.rb index d53ce6a..ffb6b92 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/default.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/default.rb @@ -265,7 +265,11 @@ service "mastodon-streaming" do action [:enable, :start] end -# Delete old media cache +# +# Delete cached remote media older than 30 days +# Will be re-fetched if necessary +# + systemd_unit 'mastodon-delete-old-media-cache.service' do content({ Unit: { @@ -273,12 +277,12 @@ systemd_unit 'mastodon-delete-old-media-cache.service' do }, Service: { Type: "oneshot", - WorkingDirectory: "#{mastodon_path}", - Environment: "\"RAILS_ENV=#{rails_env}\"", + WorkingDirectory: mastodon_path, + Environment: "RAILS_ENV=#{rails_env}", ExecStart: "#{bundle_path} exec bin/tootctl media remove --days 30", - SyslogIdentifier: "mastodon-delete-old-media-cache" } }) + triggers_reload true action [:create] end @@ -292,10 +296,9 @@ systemd_unit 'mastodon-delete-old-media-cache.timer' do Persistent: 'true' }, Install: { - WantedBy: 'timers.target' + WantedBy: 'timer.target' } }) - triggers_reload true action [:create, :enable, :start] end