From 5017b3ad78f126add9896a937b4af6e41ea28503 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 29 Jan 2023 19:46:47 +0000 Subject: [PATCH] Add mastodon cleanup script --- ansible/roles/mastodon/files/purge-media.sh | 10 ++++++++++ ansible/roles/mastodon/tasks/main.yml | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 ansible/roles/mastodon/files/purge-media.sh diff --git a/ansible/roles/mastodon/files/purge-media.sh b/ansible/roles/mastodon/files/purge-media.sh new file mode 100644 index 0000000..0a3ea7e --- /dev/null +++ b/ansible/roles/mastodon/files/purge-media.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -ex + +cd /opt/mastodon + +docker-compose exec mastodon tootctl media remove --days=7 +docker-compose exec mastodon tootctl statuses remove --days=7 +docker-compose exec mastodon tootctl preview_cards remove --days=7 +docker-compose exec mastodon tootctl cache clear diff --git a/ansible/roles/mastodon/tasks/main.yml b/ansible/roles/mastodon/tasks/main.yml index 4f3491c..ddd96c8 100644 --- a/ansible/roles/mastodon/tasks/main.yml +++ b/ansible/roles/mastodon/tasks/main.yml @@ -18,3 +18,21 @@ validate: docker-compose -f %s config notify: restart mastodon become: true + +- name: Install media cleanup script + template: + src: files/purge-media.sh + dest: /opt/mastodon/purge-media.sh + mode: "0755" + owner: "{{ docker_user.name }}" + become: true + +- name: Schedule media cleanup + cron: + name: clean up mastodon media + hour: 2 + minute: 0 + weekday: 1 + job: /opt/mastodon/purge-media.sh + user: "{{ docker_user.name }}" + become: true