日期: 2022年4月3日

  • 记一次升级Mastodon的过程(3.4.6->3.5.0)

    最近发现Mastodon有新的版本了,所以准备进行一次小版本升级,遂在此记录升级过程。
    说明下实例情况:

    • 非Docker实例
    • Postgresql 12
    • Mastodon安装在 /home/mastodon/live
    • 操作系统 Ubuntu 20.04
    • 旧版本为 3.4.6 ,准备升级至 3.5.0

    本次更新会涉及到数据库操作,所以建议在升级前备份数据库。

    su postgres #切换至postgresql所在用户
    pg_dumpall > all_dbdata.sql #备份所有库

    检出3.5.0代码

    su - mastodon  #切换至Mastodon所在用户
    cd /home/mastodon/live  #切换到Mastodon运行目录
    git fetch
    git checkout v3.5.0

    升级Ruby

    首先更新可用版本列表

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

    接着通过执行安装 Ruby 3.0.3

    RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 3.0.3

    最后安装依赖项: bundle installyarn install

    数据库迁移

    1. 通过指定 SKIP_POST_DEPLOYMENT_MIGRATIONS=true 环境变量运行部署前数据库迁移:
      SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production bundle exec rails db:migrate
    2. 预编译资产
      RAILS_ENV=production bundle exec rails assets:precompile
    3. 重新启动所有Mastodon进程
      systemctl restart mastodon-web mastodon-sidekiq mastodon-streaming
    4. 清理缓存
      RAILS_ENV=production /home/mastodon/live/bin/tootctl cache clear
    5. 现在新代码正在运行,我们可以完成数据库迁移。:
      RAILS_ENV=production bundle exec rails db:migrate
    6. 再次重新启动所有Mastodon进程
      systemctl restart mastodon-web mastodon-sidekiq mastodon-streaming

    至此升级结束