--> -->

skimemo


skimemo - 日記/2017-04-20/Mastodonマストドンのアップデート方法メモ のバックアップ(No.1)


_ 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が稼働環境という前提です。

  1. mastodonユーザーになる
    必ず「-」を付ける。そうしないと環境が引き継がれず、見えない穴に落ちます。。。
    $ sudo su - mastodon

  2. 必要なパッケージをインストール
    $ 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では幾つか新たに追加)

  3. node.jsのバージョンを確認し、6じゃなければ上げる
    $ node -v
    $ curl -sL https://deb.nodesource.com/setup_6.x | sudo bash -
    $ sudo apt-get install nodejs
    $ sudo npm install -g yarn

  4. 最新のリポジトリを取得
    $ 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とかになってしまう)

  5. .env.productionをコピー
    $ cp ../live/.env.production .

  6. 一部カスタマイズしたソースを新しい方にも反映
    $ diff ../live/config/environments/production.rb ./config/environments/production.rb
    で違いを確認し、意図したところだけ変わっていればコピー。
    $ cp ../live/config/environments/production.rb ./config/environments/
    そうでなければ手動で反映。
    $ vi ./config/environments/production.rb
    以前は変更しないとメールが飛ばないことがありましたが今は不要なので削除。

  7. 関連するものをインストール
    $ gem install bundler
    $ bundle install --deployment --without development test
    $ yarn install --pure-lockfile

  8. DBのmigration
    release noteを見て指示があれば実行。
    $ RAILS_ENV=production bundle exec rails db:migrate

  9. precompile
    $ RAILS_ENV=production bundle exec rails assets:precompile

  10. 取得済み画像等をコピー
    $ cp -r ../live/public/system public/

  11. 本番環境に入れ替え
    $ cd ..
    $ rm -rf live.old
    $ mv live live.old
    $ mv livenew live

  12. サービス再起動
    $ sudo systemctl restart mastodon-*.service

これでいいはず。

_ メモ

Mastodon設定時の情報がネット上に殆ど無いので、失敗例なども書き溜めてみる。(推測もそれなりに入っているのでご注意ください(^^;))

  1. db:migrateはバージョンが飛んでも大丈夫か?
    バージョンを1つずつではなく一気に数バージョン飛ばしてupdateする場合、db:migrateはどうなるのか?
    ディレクトリ ~/live/db/migrate を見ると、過去のmigrateが全て格納されている。従って、複数バージョン飛ばしても多分大丈夫。
    少なくとも1.4.1.→1.4.6は問題なかった。

  2. 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.

  3. 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できるようになる模様。
Category: [Linux] - 08:46:10