Rolling my own Mastodon
A short write-up about setting up my own Mastodon instance
2022-11-08 21:45:17 +0100 +0100
I admit I had not paid much attention to Mastodon. Sorry! But along with 70,000 others, recent events1 pushed me enough to check it out.
Can I have an account please?
My first inclination was to find a popular instance and make an account there. Mastodon is a federated network, so you can talk to others across instances. The problem is, most instances are growing so rapidly this week that administrators shut off account creation for most of the well-known ones. Even paid services like masto.host which provide fully managed hosting for a fee (note, less than $8 😉 per month) are temporarily shut.
I noticed in the docs there’s a section for “Running your own server”, thought, “how hard could this be?” (spoiler: moderately hard!) and got to work.
Hosting
This is easy. I already have a DigitalOcean account that I use for small projects from time to time. Creating a new Droplet with backups is $7.20.
Assigning a domain
This was also easy. I have some domains managed via Fastmail. Adding an A
record to point to my new server took less than a minute:
1-click install?
The running your own server docs point out that there’s a 1-click installer for DigitalOcean. That sounded intriguing, but the install version is 3.1.3 (latest version is 3.5.3), and Ubuntu image is 18.04 (latest is 22.10). So, I left that option to the side and went forward with the innocuous sounding preparing your machine docs.
Preparing your machine
This part was pretty straightforward: lock down SSH, update system packages, and set up a firewall. Rather than muck around with iptables
or ufw
I used DigitalOcean’s firewall.
Then, the difficult part, installing from source.
Installing
To be clear, this document mostly worked and some of the frustrations are due to my misreading.
In fact, right at the top it says:
A machine running Ubuntu 20.04 or Debian 11 that you have root access to
while I am running 22.10. This probably led to some of the subtle annoyances which I’ll outline quickly here:
- The node JS install script actually installs node 18, but Mastodon docs assume node 16. I didn’t realize that until later, though.
corepack
andyarn
were not found after installing the suggested list of system packagesrbenv install
complained aboutinstall
not being a valid command. This StackOverflow post pointed me in the right direction.yarn install
failed (loudly) due toError: error:0308010C:digital envelope routines::unsupported
. I switched to node 16 usingnvm
and moved forward- later, it came time to compile the JS assets. This time I got
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory node
. I (mistakenly) thought the issue was due to not having swap, so after creating a swap partition, failing again, increasing its size further, failing once more, I realized that I had to set the memory fornode
like so:NODE_OPTIONS="--max-old-space-size=4096" RAILS_ENV=production bin/rails assets:precompile
Certbot
continues to be an amazing thing and no complaints there, only that it added a new section to the nginx config, while the docs provided an example set of configuration that had additional web server settings. So I had to manually copy over Cerbot’s additions to the supplied config, and disable the addition that Certbot made.
tl;dr if you build from source yourself, you should probably use Ubuntu 22.04 or Debian 11, and not Ubuntu 22.10 to save your self some headache.
Success!
After all that, I was able to create an account for myself with the CLI. And the result:
I spent a bit of time looking around at how to get linked up with other instances and then realized I just had to start following accounts!
I did some basics like 1) shutting off account registration, as this is just for myself, for now, and 2) setting up 2FA. Everything was easy and intuitive in the admin.
So, there is my $7.20 and ~45 minute tale of setting up my Mastodon instance. Not sure how long I’ll keep it going before migrating to an instance managed by someone more responsible than me, but I love that this is even a possibility. See you there!
a.k.a repugnant billionaire taking an axe to human rights and content moderation teams, among other things. ↩︎