Updating mastodon (v4.0.2 to v4.1.2)

Updating mastodon (v4.0.2 to v4.1.2)
Photo by Markus Winkler / Unsplash
These steps are based on updating from v4.0.2 to v4.1.2. And is based on my installation (instructions are here). Hopefully you might get some use out of this if you need to update your machine, but I make no promises.

Login on the machine using ssh (root@instance) and then login as mastodon super user

# Login as superuser
su - mastodon

Backup the database (create the backups folder if missing and don't forget to update the date).

pg_dump --dbname=mastodon_production --host=/var/run/postgresql --port=5432 --username=mastodon -f backups/database-backup-2023-05-27

Also backup the .env file (since it contains your secrets). Only needs to be done the first time since this file in theory doesn't change. The SQL database and secrets are the only things you need to restore everything.

cp live/.env.production backups/

Go to the live folder and retrieve all releases.

cd live
git fetch --tags

And at this point you will need to look at the releases of mastodon and see what needs to be changed (note: You need to check each release in between since not the overview page don't always show the entire content of each release post, so some instructions might be not be visible). In this case I had to perform the following:

# Update ruby
git -C /home/mastodon/.rbenv/plugins/ruby-build pull
# Update the code
git checkout v4.1.2
# Install dependencies
bundle install
yarn install

Then I rebooted the machine. The site still worked, but when I checked admin page it said there was still a database migration pending. Luckily that was easy.

RAILS_ENV=production bundle exec rails db:migrate

Reloading the page and now everything was working again. 🥳