_ Mastodonマストドンのアップデート方法メモ
マストドンMastodonのアップデートがとりあえずできたようなので、手順を記録しておく。
ちなみに環境はこれ。
$ uname -a
Linux mstdn 4.4.0-72-generic #93-Ubuntu SMP Fri Mar 31 14:07:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
~/liveが稼働環境という前提です。
- mastodonユーザーになる
必ず「-」を付ける。そうしないと環境が引き継がれず、見えない穴に落ちます。。。
$ sudo su - mastodon
- 必要なパッケージをインストール
$ sudo apt-get install pkg-config libprotobuf-dev protobuf-compiler (1.3.x→1.4.1では新たに幾つか追加)
$ sudo apt-get install libicu-dev libidn11-dev (1.5.0では幾つか新たに追加)
- node.jsのバージョンを確認し、8じゃなければ上げる
$ node -v
$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
$ sudo apt-get install nodejs
$ sudo npm install -g yarn
- 最新のリポジトリを取得
$ git clone https://github.com/tootsuite/mastodon.git livenew
$ cd livenew
$ git checkout $(git tag | grep [0-9]\.[0-9]\.[0-9]$ | tail -n 1)
(公式ドキュメントには git tag | tail -n 1 とあるが、それだと1.4rc6とかになってしまう)
- .env.productionをコピー
$ cp ../live/.env.production .
- 一部カスタマイズしたソースを新しい方にも反映
$ diff ../live/config/environments/production.rb ./config/environments/production.rb
で違いを確認し、意図したところだけ変わっていればコピー。
$ cp ../live/config/environments/production.rb ./config/environments/
そうでなければ手動で反映。
$ vi ./config/environments/production.rb
以前は変更しないとメールが飛ばないことがありましたが今は不要なので削除。
- 関連するものをインストール
$ gem install bundler
$ bundle install --deployment --without development test
$ yarn install --pure-lockfile
- DBのmigration
release noteを見て指示があれば実行。
$ RAILS_ENV=production bundle exec rails db:migrate
- precompile
$ RAILS_ENV=production bundle exec rails assets:precompile
- 定期的に画像キャッシュ削除していない場合はコピー前に削除
$ RAILS_ENV=production bundle exec rake mastodon:media:remove_remote
- 取得済み画像等をタイムスタンプを維持しながらコピー
$ cp -r -a ../live/public/system public/
容量が足りない場合は以下で稼ぐ。
$ RAILS_ENV=production bundle exec bin/tootctl media remove --days=3 --verbose
(直近3日分だけ残して画像を削除する)
$ yarn cache clean
(私の場合は1GBぐらい消えた。容量によっては1〜2分かかる)
- 本番環境に入れ替え
$ cd ..
$ rm -rf live.old
$ mv live live.old
$ mv livenew live
- サービス再起動
restartだとうまく再稼働しない場合があるようなので一旦止めて再始動。
$ sudo systemctl stop mastodon-*.service
$ sudo systemctl start mastodon-web.service
$ sudo systemctl start mastodon-streaming.service
$ sudo systemctl start mastodon-sidekiq.service
これでいいはず。
_ メモ
Mastodon設定時の情報がネット上に殆ど無いので、失敗例なども書き溜めてみる。(推測もそれなりに入っているのでご注意ください(^^;))
- db:migrateはバージョンが飛んでも大丈夫か?
バージョンを1つずつではなく一気に数バージョン飛ばしてupdateする場合、db:migrateはどうなるのか?
ディレクトリ ~/live/db/migrate を見ると、過去のmigrateが全て格納されている。従って、複数バージョン飛ばしても多分大丈夫。
ただし、v2.4.1以降はv2.4.1の状態に依存しているらしく、2.4.1をまたげない。つまり、2.4.1以前から2.4.1以降にバージョンアップする場合、一旦v2.4.1のdb:migrateを実行してから最新版のmigrateを実行する必要がある。これをしないと、以下のエラーが発生する。
Index name 'index_statuses_20180106' on table 'statuses' already exists
これを#8001によってうまく回避しても、#8007でひっかかる。
-- Deduplicating @luclu7@7nw.eu (1 duplicates)...
Creating scope :cache_ids. Overwriting existing method Notification.cache_ids.
rails aborted!
StandardError: An error has occurred, all later migrations canceled:
PG::UndefinedTable: ERROR: relation "custom_filters" does not exist
LINE 8: WHERE a.attrelid = '"custom_filters"'::regcla...
- ruby.hが見つからないエラー
bundle install時に以下のエラーが出てしまう。
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
これは、ユーザーmastodonの環境が不完全な時に発生する模様。
私の場合は、linuxに他のユーザーでログインした後、mastodonユーザーにsuしているが、このとき「-」を忘れて環境変数の読み込みを行わなくて発生した。
下手にruby.hを見つけ出して、
sudo ln -s /usr/include/ruby-2.3.0/ /usr/lib/ruby/include
とかすると、一見bundle installは通るが、Mastodonが起動しない。
● mastodon-sidekiq.service - mastodon-sidekiq
Loaded: loaded (/etc/systemd/system/mastodon-sidekiq.service; enabled; vendor preset: enabled)
Active: inactive (dead) (Result: exit-code) since Sat 2017-06-24 08:51:53 JST; 1s ago
Process: 25609 ExecStart=/home/mastodon/.rbenv/shims/bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push (code=exited, st
Main PID: 25609 (code=exited, status=127)
Jun 24 08:51:52 mstdn systemd[1]: mastodon-sidekiq.service: Main process exited, code=exited, status=127/n/a
Jun 24 08:51:52 mstdn systemd[1]: mastodon-sidekiq.service: Unit entered failed state.
Jun 24 08:51:52 mstdn systemd[1]: mastodon-sidekiq.service: Failed with result 'exit-code'.
Jun 24 08:51:53 mstdn systemd[1]: mastodon-sidekiq.service: Service hold-off time over, scheduling restart.
Jun 24 08:51:53 mstdn systemd[1]: Stopped mastodon-sidekiq.
Jun 24 08:51:53 mstdn systemd[1]: mastodon-sidekiq.service: Start request repeated too quickly.
Jun 24 08:51:53 mstdn systemd[1]: Failed to start mastodon-sidekiq.
- yarnのバージョン
2.0.0でprecompileすると以下のようなエラーが出て止まってしまう。
Webpacker requires Yarn >= 0.25.2 and you are using 0.24.5
Please upgrade Yarn https://yarnpkg.com/lang/en/docs/install/
こちらのページより、yarnの中身? のupdateをしてみる。
$ sudo npm update -g yarn
するとprecompileできるようになる模様。
- .ruby-version
v2.0以降、Rubyの推奨バージョンが2.4.2になった。このため、それ以前の環境ではgem install bundler時に以下のエラーが出る。
$ gem install bundler
rbenv: version `2.4.2' is not installed (set by /home/mastodon/livenew/.ruby-version)
ただ、今のところ推奨環境であって必須では無いので、.ruby-versionファイルを書き換えれば動く。
$ vi .ruby-version
2.4.2→2.4.1
v2.5.0以降、Rubyの推奨バージョンが2.5.3になった。いい加減上げよう。
$ cd ~/.rbenv/plugins/ruby-build
$ git pull origin master
2.5.3がリストに追加されていることを確認。
$ rbenv install -l | grep 2.5.3
2.5.3
インストール
$ cd ~/live
$ rbenv install 2.5.3
...数分(私の場合は4分ぐらい)待つ。
心配ならtopコマンドでタスクを確認。c1とかが動いていればコンパイル中。
バージョンの確認。
$ ruby --version
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
Category: [
Linux] - 08:46:10