[MASTODON 4.2.10] How to update Mastodon to a new version

Updated on 26-08-2024. For the old version, click here.

Contents:
1. UPDATE
2. RUBY VERSION ISSUES
3. RUBY GEM ISSUES
4. CHARLOC_HOLMES GEM ISSUES

So a new release came out and it is important to get this update as soon as possible! This manual is a transcript of the way that I have updated my Mastodon instance. Please make sure you make proper backups and use your brain while updating things.

A guide to making a Mastodon backup can be found here.

Linux flavour: Debian
Update from: 4.2.xx

  1. Log into your server
  2. su - mastodon
  3. cd /home/mastodon/live
  4. git fetch --tags
  5. git checkout [type the most recent version here, starting with the letter v. For example; v4.2.5
    git checkout v4.2.10
  6. If you get a ruby version error, please see bottom of this article for a fix! bundle install
  7. yarn install
  8. RAILS_ENV=production bundle exec rails db:migrate
    
    #NOTE: You might get a ruby error which then suggests you to enter the command "bundle install". Do that and then run the RAILS command again.
  9. RAILS_ENV=production bundle exec rails assets:precompile
  10. exit

OPTIONAL:
After updating, you might get a notification to update the browserlist database. You can do that with the following command:

npx update-browserslist-db@latest

Okay, you can now choose to either reboot or restart the services.

REBOOT:

  1. This command may vary, depending on your Linux flavour.
    systemctl reboot

RESTART:

  1. This command may vary, depending on your Linux flavour.
    systemctl restart mastodon-sidekiq
    systemctl reload mastodon-web
    
    

    Optional:

    systemctl restart mastodon-streaming

RUBY VERSION ISSUES

My system was unable to find the required v3.2.3 of Ruby and I have fixed this by doing the following steps:

  1. Please make sure that your path is correct.
    git -C ~/.rbenv/plugins/ruby-build pull
  2. rbenv install 3.2.3
    
    

    *WAIT TILL DONE* (it may take a little while)

  3. To check all the installed versions type:
    rbenv versions
  4. To set v3.2.3 as the global version, type:
    rbenv global 3.2.3
  5. To double-check the active, installed version, type:
    rbenv versions
  6. Done!

This manual is a transcript of the way that I have updated my Mastodon instance. Please make sure you make proper backups and use your brain while updating things.

Sources: https://richstone.io/where-is-ruby-3-0-0-on-rbenv/

RUBY GEM ISSUES

After entering…

RAILS_ENV=production bundle exec rails db:migrate

…you might get a ruby gem error like:

Could not find rexml-3.3.5, strscan-3.1.0 in locally installed gems
Run `bundle install` to install missing gems.

Enter the command “bundle install” and after that run the RAILS command again.

CHARLOCK_HOLMES ISSUES

The charlock_holmes gem may fail to build on some systems with recent versions of gcc. If you run into such an issue, try

BUNDLE_BUILD__CHARLOCK_HOLMES="--with-cxxflags=-std=c++17" bundle install.

Loading

Increasing the character limit on Mastodon 4.1.x and 4.2.x

There is a very small difference between the two Git branches, so pay attention.

su - mastodon

Edit if your Mastodon instance is v4.1.x

nano live/app/javascript/mastodon/features/compose/components/compose_form.js

Edit if your Mastodon instance is v4.2.x

nano live/app/javascript/mastodon/features/compose/components/compose_form.jsx

In this file, you will find the number “500” twice. Replace that number with your desired character limit and save the file.

nano live/app/validators/status_length_validator.rb

In this file, you will find the number “500” once. Replace that number with your desired character limit and save the file.

nano live/app/serializers/rest/instance_serializer.rb

FIND the line that reads:

:languages, :registrations,

ADD the following to that line:

:max_toot_chars

Pay attention if a comma is used at the end or not.

Scroll down to the end of the file until you reach the “private” section.

ADD

def max_toot_chars 
[the number of your desired character limit without the brackets]
end

EXAMPLE

def max_toot_chars 
5000
end

Go back to the live directory and enter the following commands, one by one:

RAILS_ENV=production bundle exec rails assets:precompile
exit
systemctl restart mastodon-sidekiq
systemctl reload mastodon-web
[OPTIONAL] systemctl restart mastodon-streaming

Done.

Loading

How to update Mastodon to a new version

EXPIRED: NEW GUIDE AVAILABLE HERE

Updating Mastodon and creating backups are important steps to ensure the security and stability of your instance. Here’s a comprehensive tutorial on how to update Mastodon, including making backups of the database and assets:


Note 1: Always perform updates on a test/staging instance before applying them to your live instance. This tutorial assumes you have some basic command line and server administration knowledge.

Note 2: If you made alterations to your files and want to update to a new branch, like v4.2.0, don’t forget to stash your files first. DO THIS AT YOUR OWN RISK.

cd /home/mastodon/live
git stash

You will not have an error message any more when entering:
I currently do not know how to put the stashed files back, this will be found out later.

git checkout v4.2.0

Note 3: If you switch to a new branch and version, like 4.2.0, you might run into an error stating the following:

rbenv: version '3.2.2' is not installed (set by /home/mastodon/live/.ruby-version)

Take the following steps to solve this problem:
(Type the version you need where it says x.x.x)

rbenv install x.x.x

If that fails, try the following command:

brew update && brew upgrade ruby-build

Followed by:
(Type the version you need where it says x.x.x)

rbenv install x.x.x

OPTIONAL: If bundler or rails fails to work, try the following commands:

gem install bundler

gem install rails

Click here for the backup steps. It basically comes down to a Database dump, a settings file backup and a Redis dump. If you wish to backup your assets like images and stuff (User-uploaded files), backup the folder named “public/system”. Keep in mind that this folder can be rather large. Actually, it can become rather massive.

After a good 90 minutes, I gave up on trying to show you how large the asset folder is. So beware if you are going to make a backup of it. Perhaps you can just skip the cache folder?

You can always check the folder size by using NCDU, for which you can find the manual here. Also, installations may vary, but this is an example of my instance.


Upgrade procedure.

  1. su - mastodon
  2. cd /home/mastodon/live
  3. git fetch --tags
  4. git checkout [type the most recent version here, starting with the letter v. For example; v4.0.1
    
    Command example: git checkout v4.0.1
  5. bundle install
  6. yarn install
  7. RAILS_ENV=production bundle exec rails db:migrate
  8. RAILS_ENV=production bundle exec rails assets:precompile
  9. exit
  10. reboot now

And that should be it!

If you don’t want to restart your server, use the following commands instead of “reboot now”:

  1. exit
  2. systemctl restart mastodon-sidekiq
  3. systemctl reload mastodon-web

    The reload operation is a zero-downtime restart, also called a “phased restart”. As such, Mastodon upgrades usually do not require any advance notice to users about planned downtime. In rare cases, you can use the restart operation instead, but there will be a (short) felt interruption of service for your users.

  4. The streaming API server is also updated and requires a restart; doing so will result in all connected clients being disconnected, which can increase the load on your server:
systemctl restart mastodon-streaming

Done!

PS: When I updated my instance from 4.1.9 to 4.2.0, a lot of warnings flew by, and this is, in my experience, not a problem as the instance is working perfectly.

Loading

Mastodon: Manual backups

This is an updated version (26-08-2024)

This manual is a transcript of the way that I have made a backup of my Mastodon instance. Please make sure you are careful and use your brain while following this manual.

Preparing the backup folder

  1. Log in as root
  2. cd /home/mastodon
  3. mkdir backups
  4. cd backups

Making the backups

  1. Database (three steps)
  2. #NOTE: You might need to elevate to ROOT first before entering the commands in this section below.
    su - mastodon
    cd /home/mastodon/backups
    pg_dump -U mastodon mastodon_production -F t > DATE_FILENAME.tar
    
    

    Example: pg_dump -U mastodon mastodon_production -F t > 2024-02-02-mastodon_production.tar

  3. Settings file (one step)
    cp /home/mastodon/live/.env.production /home/mastodon/backups/DATE_.env.production
    
    

    Example: cp /home/mastodon/live/.env.production /home/mastodon/backups/2024-02-02-.env.production

  4. Redis (two steps, perform as root)
    exit
    cp /var/lib/redis/dump.rdb /home/mastodon/backups/DATE_dump.rdb
    
    

    Example: cp /var/lib/redis/dump.rdb /home/mastodon/backups/2024-02-02-REDIS-dump.rdb

You can now check your backups folder to see if all three files are present. This is also a good moment to copy the backup files to another, safe, location.

If you wish to backup your assets like images and stuff (User-uploaded files), backup the folder named “public/system”. Keep in mind that this folder can be rather large. Actually, it can become rather massive.

Loading

Mastodon: “There are pending database migrations. Please run them to ensure the application behaves as expected”

“There are pending database migrations. Please run them to ensure the application behaves as expected” or “Niet alle databasemigraties zijn voltooid. Je moet deze uitvoeren om er voor te zorgen dat de applicatie blijft werken zoals het hoort” can be solved with the following command, executed as user mastodon:

1.
su - mastodon
2. 
cd live
3.
RAILS_ENV=production bundle exec rails db:migrate

results in:

Loading