Skip to content

Instantly share code, notes, and snippets.

@umonaca
Last active June 30, 2020 09:22
Show Gist options
  • Save umonaca/632ab624adf2075fa6493ac7ab5b79ca to your computer and use it in GitHub Desktop.
Save umonaca/632ab624adf2075fa6493ac7ab5b79ca to your computer and use it in GitHub Desktop.
升级指南

升级指南

备份好全站数据库。node最低10建议12,ruby 2.6.6.

主要功能上的变化是:

  • 增加一个在federated timeline和hashtag timeline上去除/显示本地toot的界面开关和相应的API endpoint

/api/v1/timelines/public 参数remote boolean

streaming增加public/remote / public:remote

升级Node

如果已经在用node v12,跳过此步骤。

方法很多,可以用n或者nvm,源码根目录下有一个.nvmrc文件里面是写的12。不建议变更整个系统的node版本。最后可以用node -v确认当前版本号。 须注意systemd所使用的node版本可能仍然是已经过时的node 8. 正确的做法是修改/etc/systemd/system/mastodon-streaming.service中的node路径为node v12版本的路径,然后systemctl daemon-reload & systemctl restart mastodon-streaming.service

升级ruby

rbenv是以当前文件夹下的.ruby-version为准的,所以以下步骤不会影响服务器运行。systemd service使用的也是rbenv文件夹。安装编译2.6.6需要很长时间,快的几分钟,慢的话大概十几到二十分钟左右。

su - mastodon
cd ~/.rbenv && git pull
pushd ~/.rbenv/plugins/ruby-build && git pull && popd
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 2.6.6
rbenv global 2.6.6
gem update --system

注意一定要有RUBY_CONFIGURE_OPTS=--with-jemalloc,可以节省一半内存。 然后进行以下步骤。

升级步骤

升级node版本为12,安装ruby 2.6.6以后进行如下操作。

cd ~/live && git pull
bundle config deployment 'true'
bundle config without 'development test'
bundle install \
  -j$(getconf _NPROCESSORS_ONLN) 
yarn install --pure-lockfile

然后进行常规升级和迁移操作: 注意这里包含前后两步数据库迁移。(不过由于最近代码里没有post deployment migration,如果是从非常近期的版本升级,后一步执行时其实什么都不会做。)

RAILS_ENV=production SKIP_POST_DEPLOYMENT_MIGRATIONS=true bundle exec rails db:migrate
RAILS_ENV=production bundle exec rails assets:precompile
exit
systemctl reload mastodon-web && systemctl restart mastodon-{sidekiq,streaming}
su - mastodon
cd live/
RAILS_ENV=production bin/tootctl cache clear
RAILS_ENV=production bundle exec rails db:migrate

故障排除

一般不会遇到,但如果升级出现错误可以使用以下方法:

  1. yarn install升级冲突时可以先删除所有node modules rm -rf node_modules

  2. precompile时遇到原因不明的compilation failed 应当先删除缓存再重新编译:

RAILS_ENV=production bundle exec rake tmp:cache:clear

注意如果不执行上面的命令,而是直接重新执行precompile,会直接使用缓存从而提示everything ok,但实测更新并没有上线。 如果仍然无法解决,最后的手段如下,生产环境下会导致网站一段时间内报错,可以先关闭nginx让网站下线 RAILS_ENV=production bundle exec rake assets:clobber assets:precompile

05.23.2020更新: 已查明开发站编译失败的原因是编译时内存不足。可以在线启用swapfile,然后按上面的步骤清除缓存即可。 在线启用swapfile方法,见这里。

  1. 删除/var/cache/nginx下的缓存

  2. ruby的版本号出问题的时候使用 rbenv install 解决

05.14.2020 更新

bundle即将不再使用without参数,所以上面改为

bundle config deployment 'true'
bundle config without 'development test'
bundle install -j$(getconf _NPROCESSORS_ONLN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment