Update Mastodon server instance

You might have already noticed I use Mastodon for my main fediverse handle @gytis@mastodon.lt. Just recently version 2.8.0 was released – see what's new there or on GitHub.

While typically updating Mastodon is quite straightforward, this time I needed to iterate Ruby version on the server as well.

That was visible from error thrown:

rbenv: version `2.6.1' is not installed (set by live/.ruby-version)

So the full upgrade sequence is following:

Retrieve Mastodon source updates

Switch or login to user which is running Mastodon and execute following:

cd ~/live
git fetch --tags
git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)

You might get error here:

error: Your local changes to the following files would be overwritten by checkout:
	.ruby-version
Please commit your changes or stash them before you switch branches.
Aborting

In that case reset git:

git reset --hard

And try checkout again.

Update Ruby

cd ~/.rbenv/plugins/ruby-build
git pull
cd ~/.rbenv
rbenv install 2.6.1

This was also documented in issue 638.

Update Mastodon

cd ~/live

Update Ruby dependencies

bundle install --deployment --without development test

Update node.js dependencies

yarn install --pure-lockfile

Database schema updates

RAILS_ENV=production bundle exec rails db:migrate

Pre-compiling updated assets

RAILS_ENV=production bundle exec rails assets:precompile

Restart services

Mastodon runs in memory so you will need to restart it for any of the previous updates to take effect.

Switch to root or run in sudo:

systemctl restart mastodon-*.service

Or restart services separately:

systemctl restart mastodon-web
systemctl restart mastodon-sidekiq
systemctl restart mastodon-streaming

There we go – Mastodon 2.8.0 with polls functionality running fine 😊 Try out my poll about Go code retrieval 👍