Hello from the future! I've got an updated guide over here, Mastodon Maintenance now With Systemd! It has more info that you may find handy, and will still work fine with crontab entries!

Hey there, readers!

For those of you who are running, or want to run, a mastodon instance, quick heads up:

Crontabbing it is a little bit of a pain due to having to get all the right variables brought into crontab. And, searching for how to do this properly on Google brings up outdated github based documentation. So without further ado, here's a bit of information for you!

Management Commands

At the time of writing, the documentation only has the tootctl mentioned in passing, with only its account creation method mentioned. To get more information on the commands, do live/bin/tootctl help to get a list of the categories. Later on, I think I'll make a page with all its builtin docs for quick and easy reference. but for now, let's look at the two main maintenance options tootctl statuses remove and tootctl media remove will be your best friends in this exercise for manual cleanup.

These commands will cull the database and file structure, looking for tweets and media that originated remotely -- data that came from other instances that you likely have not interacted with, or can be easily be re-obtained if requested.

Crontabbing it

Now, adding these commands, even with full path, won't Just Work sadly, as there are a number of environment variables that need to be present. What is the easiest way to do this? A quick little shell script jobbie, of course!

I've found that the following script works well:

#!/bin/bash
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export RAILS_ENV=production

/home/mastodon/live/bin/tootctl statuses remove --days=3
/home/mastodon/live/bin/tootctl media remove --days=3

Create this script, chmod +x nameofscript.sh, then add it to your crontab. The days option is put in place because I have limited space on my VPS, and the default is a week. I'm going to keep an eye out on my instance growth, and I may have to move it. Oh well, that's what I get for reusing a VPS meant for only a VPN, so little disk is provisionable as a result!

Next Post Previous Post