Updating DigitalOcean Mastodon Droplet from 3.1.3 to 4.0.2

Mastodon v4.0.2 is out, and has some handy-looking new features. But if you’re using the old DigitalOcean droplet, which was based on v3.1.3, upgrading is a bit of a faff.

Here’s how I did it – in two stages. I should not upfront that this isn’t a *recomended* method – it’s just what worked for me, in case it’s useful.

1) Upgrade to 3.5.3

Rather than attempting a straight upgrade to 4.0.2, I went to 3.5.3 first. This clears a number of potential roadblocks.

First, before doing anything, I created a Snapshot of the server as a disaster recovery backup.

Next, SSH in as root@ and backup the database. I did that as:

sudo su postgres
cd ~
pg_dump mastodon_production > dbbackup1511
exit

Then switch to the mastodon user, and get the new code:

su mastodon
cd /home/mastodon/live
git fetch && git checkout v3.5.3

The next step would be to run bundle install – but for me that failed due to an old version of Ruby. So I updated that:

git -C /home/mastodon/.rbenv/plugins/ruby-build pull
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 3.0.3

I don’t work with Ruby much, so my reference for that is this thread on Github. Now with 3.0.3 installed:

bundle install

yarn install

SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production bundle exec rails db:migrate

But then another block: to proceed I needed to update Rails as well. I went up to v16 – to do that, switch out to root user and:

curl -sL https://deb.nodesource.com/setup_16.x | bash -
sudo apt-get install -y nodejs

With Rails updated:

su mastodon
cd /home/mastodon/live
RAILS_ENV=production bundle exec rails assets:precompile

and the finally:

systemctl reload mastodon-web && systemctl restart mastodon-sidekiq mastodon-streaming
RAILS_ENV=production bin/tootctl cache clear
RAILS_ENV=production bundle exec rails db:migrate

Note that you need the root password a few times there.

This brought me up to 3.5.3. I tested a bit, restarted the server – all appeared to run fine.

2) Upgrading from 3.5.3 to v4.0.2

The instructions for going from 3.5.3 to 4.0.2 are here, and I found this stage generally much simpler.

First, backup again – maybe a snapshot, definitely a pg_dump – you can use the same procedure as before. Then:

su mastodon
/home/mastodon/live
git fetch && git checkout v4.0.2

At this point, per the instructions, I edited .ruby-version from 3.0.4 to 3.0.3 – use whatever editor you prefer; Nano is available.

With that done, the rest of the install is just a matter of following the guide:

bundle install
yarn install

SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production bundle exec rails db:migrate

RAILS_ENV=production bundle exec rails assets:precompile

systemctl reload mastodon-web && systemctl restart mastodon-sidekiq mastodon-streaming

RAILS_ENV=production bundle exec rails db:migrate

systemctl reload mastodon-web && systemctl restart mastodon-sidekiq mastodon-streaming

Posted

in

by