Mastodon をアップデートする (1.1.2 → 2.0.0)

Mastodon を CentOS にインストールする (Docker未使用)」でインストールしたっきり長らく放置していた Mastodon をアップデートした際の手順についての記録です。
※雑に記録してあるだけなので後でアップデートする予定。一部よくわからずに叩いてるコマンドあり。

現在バージョンの確認

cd /home/mastodon/live
git tag | tail -n 1

v1.1.2 でした。すみませんすみません。

その他バージョン情報

  • CentOS Linux release 7.3.1611 (Core)
  • Node.js 7.10.1
  • Ruby 2.4.1
  • Yarn 0.22.0

バックアップ

ファイル一式

df -h
cd /home/mastodon/live
cp -a /home/mastodon /home/mastodon_`git tag | tail -n 1`

どちらかというと /live/public/system をコピーしておくのが本来的だが、差し戻しが容易なように完全コピーしておく。容量に注意。

PostgreSQL

pg_dump -w -U postgres -h localhost mastodon | gzip > ~/mastodon_`date +%F_%H%M`.sql.gz

Redis

rpm -ql redis | grep redis.conf$  # /etc/redis.conf
grep ^dir /etc/redis.conf         # dir /var/lib/redis
grep ^dbfilename /etc/redis.conf  # dbfilename dump.rdb
redis-cli dbsize
redis-cli bgsave
date --date "@$(redis-cli lastsave)" +"%F %H:%M:%S"
cp -av /var/lib/redis/dump.rdb ~/redis_$(date --date "@$(redis-cli lastsave)" +"%F").rdb

アップデート

1.1.2 → 1.2

su - mastodon
cd /home/mastodon/live
git describe --tags  # v1.1.2-53-g3b8908c
git fetch
git stash
git checkout -b v1.2
bundle install && yarn install
RAILS_ENV=production bundle exec rails db:migrate
exit
systemctl restart mastodon-{web,sidekiq,streaming} redis nginx

1.2 → 1.2.2

su - mastodon
cd /home/mastodon/live
git describe --tags  # v1.2
git fetch
git stash
git checkout v1.2.2
RAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=production bundle exec rails assets:clobber
RAILS_ENV=production bundle exec rails assets:precompile
rake tmp:cache:clear
RAILS_ENV=production bundle exec rails runner 'Rails.cache.clear'
exit
systemctl restart mastodon-{web,sidekiq,streaming} redis nginx

1.2.2 → 1.3

su - mastodon
cd /home/mastodon/live
git describe --tags  # v1.2.2
git fetch
git stash
git checkout v1.3
bundle install && yarn install
RAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=production bundle exec rails assets:clobber
RAILS_ENV=production bundle exec rails assets:precompile
rake tmp:cache:clear
RAILS_ENV=production bundle exec rails runner 'Rails.cache.clear'
exit
systemctl restart mastodon-{web,sidekiq,streaming} redis nginx

1.3 → 1.3.2

su - mastodon
cd /home/mastodon/live
git describe --tags  # v1.3
git fetch
git stash
git checkout v1.3.2
bundle install && yarn install
RAILS_ENV=production bundle exec rails assets:clobber
RAILS_ENV=production bundle exec rails assets:precompile
rake tmp:cache:clear
RAILS_ENV=production bundle exec rails runner 'Rails.cache.clear'
exit
systemctl restart mastodon-{web,sidekiq,streaming} redis nginx

1.3.2 → 1.3.3

su - mastodon
cd /home/mastodon/live
git describe --tags  # v1.3.2
git fetch
git stash
git checkout v1.3.3
bundle install
rake tmp:cache:clear
RAILS_ENV=production bundle exec rails runner 'Rails.cache.clear'
exit
systemctl restart mastodon-{web,sidekiq,streaming} redis nginx

1.3.3 → 1.4.1

yum -y install pkgconfig protobuf-{devel,compiler}
su - mastodon
cd /home/mastodon/live
git describe --tags  # v1.3.3
git fetch
git stash
git checkout v1.4.1
bundle install && yarn install
RAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=production bundle exec rails assets:clobber
RAILS_ENV=production bundle exec rails assets:precompile
RAILS_ENV=production bundle exec rails runner 'Rails.cache.clear'
exit
vim /etc/nginx/nginx.conf
-user  nginx;
+user  mastodon;
systemctl restart mastodon-{web,sidekiq,streaming} redis nginx

1.4.1 → 1.4.2

su - mastodon
cd /home/mastodon/live
git describe --tags  # v1.4.1
git fetch
git stash
git checkout v1.4.2
bundle install && yarn install
RAILS_ENV=production bundle exec rails mastodon:maintenance:prepare_for_foreign_keys
RAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=production bundle exec rails assets:clobber
RAILS_ENV=production bundle exec rails assets:precompile
RAILS_ENV=production bundle exec rails r Rails.cache.clear
exit
systemctl restart mastodon-{web,sidekiq,streaming} redis nginx

1.4.2 → 1.4.6

su - mastodon
cd /home/mastodon/live
git describe --tags  # v1.4.2
git fetch
git stash
git checkout v1.4.6
bundle install && yarn install
RAILS_ENV=production bundle exec rails assets:clobber
RAILS_ENV=production bundle exec rails assets:precompile
exit
systemctl restart mastodon-{web,sidekiq,streaming} redis nginx

1.4.6 → 1.4.7

su - mastodon
cd /home/mastodon/live
gem install bundler --pre
git describe --tags  # v1.4.6
git fetch
git stash
git checkout v1.4.7
bundle install && yarn install
RAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=production bundle exec rails assets:clobber
RAILS_ENV=production bundle exec rails assets:precompile
exit
systemctl restart mastodon-{web,sidekiq,streaming} redis nginx

1.4.7 → 1.5.0

yum -y install libicu-devel libidn-devel
su - mastodon
cd /home/mastodon/live
git describe --tags  # v1.4.7
git fetch
git stash
git checkout v1.5.0
bundle install && yarn install
RAILS_ENV=production bundle exec rake mastodon:webpush:generate_vapid_key
RAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=production bundle exec rails assets:clobber
RAILS_ENV=production bundle exec rails assets:precompile
exit
systemctl restart mastodon-{web,sidekiq,streaming} redis nginx

1.5.0 → 1.5.1

su - mastodon
cd /home/mastodon/live
git describe --tags  # v1.5.0
git fetch
git stash
git checkout v1.5.1
bundle install
RAILS_ENV=production bundle exec rails assets:clobber
RAILS_ENV=production bundle exec rails assets:precompile
exit
systemctl restart mastodon-{web,sidekiq,streaming} redis nginx

1.5.1 → 1.6.0

su - mastodon
cd /home/mastodon/live
git describe --tags  # v1.5.1
git fetch
git stash
git checkout v1.6.0
bundle install && yarn install
RAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=production bundle exec rails assets:clobber
RAILS_ENV=production bundle exec rails assets:precompile
RAILS_ENV=production bundle exec rails mastodon:maintenance:remove_deprecated_preview_cards
exit
systemctl restart mastodon-{web,sidekiq,streaming} redis nginx

1.6.0 → 1.6.1

su - mastodon
cd /home/mastodon/live
git describe --tags  # v1.6.0
git fetch
git stash
git checkout v1.6.1
bundle install
RAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=production bundle exec rails assets:clobber
RAILS_ENV=production bundle exec rails assets:precompile
exit
systemctl restart mastodon-{web,sidekiq,streaming} redis nginx

1.6.1 → 2.0.0

su - mastodon
cd ~/.rbenv/plugins/ruby-build
git pull
cd ~/.rbenv
git pull
rbenv install --list | grep 2.4.2
rbenv install 2.4.2
rbenv global 2.4.2
rbenv versions
ruby -v
cd /home/mastodon/live
git describe --tags  # v1.6.1
git fetch
git stash
git checkout v2.0.0
gem install bundler
gem install bundler --pre
bundle install && yarn install
RAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=production bundle exec rails assets:clobber
RAILS_ENV=production bundle exec rails assets:precompile
exit
systemctl restart mastodon-{web,sidekiq,streaming} redis nginx

情報収集

各バージョンの Update notes 確認

https://github.com/tootsuite/mastodon/releases
リリース一覧から現在バージョン以降の各バージョンの Upgrade notes を確認します。
見た感じ rc はすっ飛ばして良さそうです。

1.4.1 (1.4rc1) から pkg-config libprotobuf-dev protobuf-compiler が、 1.5.0 (1.5.0rc1) から libicu-dev libidn11-dev が新たに要求されるようです。
CentOS でのパッケージ名はそれぞれ pkgconfig protobuf-devel protobuf-compiler libicu-devel libidn-devel となるようです。

1.2 1

  • This release includes dependency updates, that means you need to run bundle install and yarn install (not required in Docker deployments)
  • This release includes database migrations, that means you need to run RAILS_ENV=production bundle exec rails db:migrate (in Docker: docker-compose run --rm web rails db:migrate)

1.2.2 2

  • This release includes database migrations, that means you need to run RAILS_ENV=production bundle exec rails db:migrate (in Docker: docker-compose run --rm web rails db:migrate)
  • This release includes changes to assets, that means you need to run RAILS_ENV=production bundle exec rails assets:precompile (in Docker: docker-compose run --rm web rails assets:precompile)

1.3 3

  • This release includes dependency updates, that means you need to run bundle install and yarn install (not required in Docker deployments)
  • This release includes database migrations, that means you need to run RAILS_ENV=production bundle exec rails db:migrate (in Docker: docker-compose run --rm web rails db:migrate)
  • This release includes changes to assets, that means you need to run RAILS_ENV=production bundle exec rails assets:precompile (in Docker: docker-compose run --rm web rails assets:precompile)

1.3.2 4

  • This release includes dependency updates, that means you need to run bundle install and yarn install (not required in Docker deployments)
  • This release includes changes to assets, that means you need to run RAILS_ENV=production bundle exec rails assets:precompile (in Docker: docker-compose run --rm web rails assets:precompile)

1.3.3 5

  • This release includes dependency updates, that means you need to run bundle install (not required in Docker deployments)

1.4.1 6

Non-Docker only:

  • This release switches the minimum supported Node.js version from 4 to 6
  • Three additional system packages are required: pkg-config libprotobuf-dev protobuf-compiler
  • Dependency updates: bundle install and yarn install

Docker-only:

  • Processes inside Docker no longer run as root. Existing installations will require you to change directory ownership of the uploads volume to a different UID/GID: something like sudo chown -R 991:991 public/system (the default UID/GID of the new in-Docker user is 991/991)

Both Docker and non-Docker:

  • If you have CDN_HOST set, make sure it contains the protocol part (http:// or https://), if it does not, adjust it before doing the next step
  • If you set a non-default STREAMING_API_BASE_URL, change the protocol part to ws:// or wss:// respectively
  • This release includes changes to assets, that means you need to run RAILS_ENV=production bundle exec rails assets:precompile (in Docker: docker-compose run --rm web rails assets:precompile)
  • Generated assets now live under public/packs instead of public/assets. This is mostly irrelevant but might affect some custom proxying configurations.
  • This release includes database migrations, that means you need to run RAILS_ENV=production bundle exec rails db:migrate (in Docker: docker-compose run --rm web rails db:migrate)

1.4.2 7

This release adds database-level constraints for ensure cross-referential integrity. Previously, incorrect records could have persisted due to race conditions and request timeouts in the Ruby codebase. Because Postgres cannot create the constraints if violations of the constraints already exist, I have written a rake task for cleaning up the incorrect records in the database that you should execute before the migration.

If for some reason you cannot deploy the code first without running database migrations in the process (e.g. Capistrano deployments), you can simply copypaste the code from the rake task into the Rails console and execute it that way.

Because of how Postgres executes the creation of foreign keys, if Mastodon activity is happening at the same time, the migration may fail with a "deadlock". In such a case I recommend disabling user access to Mastodon during the migration, which shouldn't take longer than a minute.

Non-Docker only:

  • Dependency updates: bundle install and yarn install

Both Docker and non-Docker:

  • Run the rake task to prepare for the database migrations: RAILS_ENV=production bundle exec rails mastodon:maintenance:prepare_for_foreign_keys (in Docker: docker-compose run --rm web rails mastodon:maintenance:prepare_for_foreign_keys)
  • This release includes database migrations, that means you need to run RAILS_ENV=production bundle exec rails db:migrate (in Docker: docker-compose run --rm web rails db:migrate)
  • This release includes changes to assets, that means you need to run RAILS_ENV=production bundle exec rails assets:precompile (in Docker: docker-compose run --rm web rails assets:precompile)
  • The upgrade from Rails 5.0 to 5.1 will break cached entities. Cache lives for 10 minutes, so you can either wait for it to go away after 10 minutes, or clear Rails cache with RAILS_ENV=production bundle exec rails r Rails.cache.clear (in Docker: docker-compose run --rm web rails r Rails.cache.clear)

1.4.4 8

Note: It is recommended to upgrade straight to 1.4.6

Non-Docker only:

  • Dependency updates: bundle install and yarn install

Both Docker and non-Docker:

  • This release includes changes to assets, that means you need to run RAILS_ENV=production bundle exec rails assets:precompile (in Docker: docker-compose run --rm web rails assets:precompile)

1.4.6 9

Both Docker and non-Docker:

  • This release includes changes to assets, that means you need to run RAILS_ENV=production bundle exec rails assets:precompile (in Docker: docker-compose run --rm web rails assets:precompile)

Upgrade notes if you are upgrading straight from 1.4.3:

Non-Docker only:

  • Dependency updates: bundle install and yarn install

Both Docker and non-Docker:

  • This release includes changes to assets, that means you need to run RAILS_ENV=production bundle exec rails assets:precompile (in Docker: docker-compose run --rm web rails assets:precompile)

1.4.7 10

Non-Docker only:

Dependency updates: bundle install and yarn install

Both Docker and non-Docker:

  • This release includes database migrations, that means you need to run RAILS_ENV=production bundle exec rails db:migrate (in Docker: docker-compose run --rm web rails db:migrate)
  • This release includes changes to assets, that means you need to run RAILS_ENV=production bundle exec rails assets:precompile (in Docker: docker-compose run --rm web rails assets:precompile)

1.5.0 11

Non-Docker only:

  • New system package dependencies: libicu-dev libidn11-dev
  • Dependency updates: bundle install and yarn install

Both Docker and non-Docker:

  • To enable Web Push notifications, you should generate a few extra secrets and put them into your environment (usually .env.production). Generate the secrets/variables with: RAILS_ENV=production bundle exec rake mastodon:webpush:generate_vapid_key (in Docker: docker-compose run --rm web rake mastodon:webpush:generate_vapid_key)
  • This release includes database migrations, that means you need to run RAILS_ENV=production bundle exec rails db:migrate (in Docker: docker-compose run --rm web rails db:migrate). There are some column data updates, so the migration may take a while if your tables have many rows. If you get a lock error, you'll need to shut down the Mastodon web process during the upgrade.
  • This release includes changes to assets, that means you need to run RAILS_ENV=production bundle exec rails assets:precompile (in Docker: docker-compose run --rm web rails assets:precompile)
  • The file sw.js (service worker definition) served from the public directory should be served with no cache headers or cache headers with max-age 0 (basically, don't cache it)
  • There are no more mandatory regular cronjobs, because all important tasks have been moved to Sidekiq. Deprecated rake tasks like mastodon:daily now do nothing.

1.5.1 12

Non-Docker only:

  • Dependency updates: bundle install

Both Docker and non-Docker:

  • This release includes changes to assets, that means you need to run RAILS_ENV=production bundle exec rails assets:precompile (in Docker: docker-compose run --rm web rails assets:precompile)

1.6.0 13

Non-Docker only:

  • Dependency updates: bundle install and yarn install

Both Docker and non-Docker:

  • This release includes database migrations, that means you need to run RAILS_ENV=production bundle exec rails db:migrate (in Docker: docker-compose run --rm web rails db:migrate).
  • This release includes changes to assets, that means you need to run RAILS_ENV=production bundle exec rails assets:precompile (in Docker: docker-compose run --rm web rails assets:precompile)
  • After database migrations, clean out old preview cards thumbnails with RAILS_ENV=production bundle exec rails mastodon:maintenance:remove_deprecated_preview_cards (in Docker: docker-compose run --rm web rails mastodon:maintenance:remove_deprecated_preview_cards)

1.6.1 14

Non-Docker only:

  • Dependency updates: bundle install

Both Docker and non-Docker:

This release includes database migrations, that means you need to run RAILS_ENV=production bundle exec rails db:migrate (in Docker: docker-compose run --rm web rails db:migrate).
This release includes changes to assets, that means you need to run RAILS_ENV=production bundle exec rails assets:precompile (in Docker: docker-compose run --rm web rails assets:precompile)

2.0.0 15

Non-Docker only:

  • The recommended Ruby version has been bumped to 2.4.2. However, it is only a recommendation. If you would like to stay with 2.4.1, simply overwrite the value in .ruby-version
  • Dependency updates: bundle install and yarn install

Both Docker and non-Docker:

  • This release includes database migrations, that means you need to run RAILS_ENV=production bundle exec rails db:migrate (in Docker: docker-compose run --rm web rails db:migrate). Depending on your database size, this migration may take a long while! It may also lead to some downtime. Make sure you have backups. This is because we are upgrading a multitude of database columns from int to bigint to make sure they're future-proof.
  • This release includes changes to assets, that means you need to run RAILS_ENV=production bundle exec rails assets:precompile (in Docker: docker-compose run --rm web rails assets:precompile)

Optionally:

  • custom.scss is no longer automatically loaded because the feature has been reworked into themes. Change to default: styles/custom.scss in config/themes.yml to restore old behaviour
Troubleshooting
  • If you have upgraded to the master branch before v2.0.0rc1 and your custom emoji now fail to load, perform this rake task: RAILS_ENV=production bundle exec rake paperclip:refresh:thumbnails CLASS=CustomEmoji

アップデート情報収集

Qiita で mastodon タグが付いてる記事からアップデートに関するものをピックアップしました。
mastodon タグが付いてる記事っていま196件もあるんですね。