Mastodonのバージョンアップやコケた時に使うコマンドとか、色々(non-Docker版) 2020/04/07更新

一先ずシステムのアップデート

```
# apt update && apt upgrade -y
```

自インスタンス用master追従用コマンド

```
# su - mastodon
mastodon@xxx$ cd live
mastodon@xxx/live$ git pull
mastodon@xxx/live$ git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)
mastodon@xxx/live$ git fetch && git checkout vX.X.X
mastodon@xxx/live$ bundle install
mastodon@xxx/live$ yarn install
mastodon@xxx/live$ RAILS_ENV=production bundle exec rails db:migrate
mastodon@xxx/live$ RAILS_ENV=production bundle exec rails assets:precompile
mastodon@xxx/live$ sudo systemctl restart mastodon-*.service
mastodon@xxx/live$ RAILS_ENV=production bin/tootctl cache clear
```
※下記コマンドでgithubを最新に同期するのを忘れずに

```
mastodon@xxx/live$ git checkout master
mastodon@xxx/live$ git pull
mastodon@xxx/live$ git push https://github.com/syumari/mastodon.git master:master
```

Rubyの更新(2.6.5→2.7.0の場合)

```
mastodon@xxx:~$ RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 2.7.0
ruby-build: definition not found: 2.7.0
See all available versions with `rbenv install --list'.
If the version you need is missing, try upgrading ruby-build:
  cd /home/mastodon/.rbenv/plugins/ruby-build && git pull && cd -
```
2.7.0なんてリストにそんな新しいのないわよ！と怒られますが
しょうがないわね、リスト更新してあげるからこのコマンド使いなさいと優しく教えてくれるUbuntuちゃんはツンデレです。

```
mastodon@xxx:~$ cd /home/mastodon/.rbenv/plugins/ruby-build && git pull && cd -
remote: Enumerating objects: 50, done.
remote: Counting objects: 100% (50/50), done.
remote: Compressing objects: 100% (33/33), done.
remote: Total 50 (delta 24), reused 28 (delta 9), pack-reused 0
Unpacking objects: 100% (50/50), done.
From https://github.com/rbenv/ruby-build
   d2a7eef..786b89f  master     -> origin/master
 * [new tag]         v20191002  -> v20191002
Updating d2a7eef..786b89f
Fast-forward
 bin/ruby-build         | 4 ++--
 share/ruby-build/2.4.8 | 2 ++
 share/ruby-build/2.4.9 | 2 ++
 share/ruby-build/2.5.7 | 2 ++
           ︙
 share/ruby-build/2.7.0 | 2 ++
 5 files changed, 10 insertions(+), 2 deletions(-)
 create mode 100644 share/ruby-build/2.4.8
 create mode 100644 share/ruby-build/2.4.9
 create mode 100644 share/ruby-build/2.5.7
 create mode 100644 share/ruby-build/2.6.5
           ︙
 create mode 100644 share/ruby-build/2.7.0
/home/mastodon

mastodon@1xxx:~$ RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 2.7.0
Downloading ruby-2.7.0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.0.tar.bz2
Installing ruby-2.7.0...

mastodon@1xxx:~$ rbenv global 2.7.0
mastodon@xxx:~$ rbenv versions
  2.6.1
  2.6.4
  2.6.5
* 2.7.0 (set by /home/mastodon/.rbenv/version)
mastodon@xxx:~$
```

bundle installしたらワケワカメになった。

```
mastodon@xxx:~/live$ bundle install
Ignoring blurhash-0.1.3 because its extensions are not built. Try: gem pristine blurhash --version 0.1.3
Ignoring bootsnap-1.4.4 because its extensions are not built. Try: gem pristine bootsnap --version 1.4.4
Ignoring charlock_holmes-0.7.6 because its extensions are not built. Try: gem pristine charlock_holmes --version 0.7.6
Ignoring cld3-3.2.4 because its extensions are not built. Try: gem pristine cld3 --version 3.2.4
Ignoring hamlit-2.9.3 because its extensions are not built. Try: gem pristine hamlit --version 2.9.3
Ignoring msgpack-1.2.10 because its extensions are not built. Try: gem pristine msgpack --version 1.2.10
Ignoring nio4r-2.5.1 because its extensions are not built. Try: gem pristine nio4r --version 2.5.1
Ignoring nio4r-2.3.1 because its extensions are not built. Try: gem pristine nio4r --version 2.3.1
Ignoring nokogiri-1.10.5 because its extensions are not built. Try: gem pristine nokogiri --version 1.10.5
Ignoring nokogiri-1.10.4 because its extensions are not built. Try: gem pristine nokogiri --version 1.10.4
Ignoring nokogiri-1.10.3 because its extensions are not built. Try: gem pristine nokogiri --version 1.10.3
Ignoring nokogumbo-2.0.0 because its extensions are not built. Try: gem pristine nokogumbo --version 2.0.0
Ignoring oj-3.9.2 because its extensions are not built. Try: gem pristine oj --version 3.9.2
Ignoring oj-3.9.1 because its extensions are not built. Try: gem pristine oj --version 3.9.1
Ignoring oj-3.7.12 because its extensions are not built. Try: gem pristine oj --version 3.7.12
Ignoring ox-2.11.0 because its extensions are not built. Try: gem pristine ox --version 2.11.0
Ignoring pg-1.1.4 because its extensions are not built. Try: gem pristine pg --version 1.1.4
Ignoring puma-4.2.0 because its extensions are not built. Try: gem pristine puma --version 4.2.0
Ignoring puma-3.12.1 because its extensions are not built. Try: gem pristine puma --version 3.12.1
Ignoring unf_ext-0.0.7.5 because its extensions are not built. Try: gem pristine unf_ext --version 0.0.7.5
Ignoring websocket-driver-0.7.0 because its extensions are not built. Try: gem pristine websocket-driver --version 0.7.0
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies........
```
そんなときは「bundle clean」で不整合な状態をクリアしちゃう

```
mastodon@vulpes:~/live$ bundle clean
Removing tty-prompt (0.20.0)
Removing discard (1.1.0)
Removing kaminari-actionview (1.2.0)
Removing css_parser (1.6.0)
Removing activerecord (5.2.4.1)
Removing http-form_data (2.1.1)
Removing json-ld-preloaded (3.0.6)
Removing elasticsearch (7.3.0)
Removing mime-types (3.2.2)
Removing nokogiri (1.10.4)
Removing rake (12.3.2)
Removing rack-protection (2.0.5)
Removing jwt (2.2.1)
Removing rake (12.3.3)
Removing erubi (1.8.0)
Removing kaminari-activerecord (1.2.0)
Removing json-ld-preloaded (3.1.0)
Removing rack (2.0.7)
Removing nokogumbo (2.0.0)
Removing necromancer (0.5.0)
Removing bcrypt (3.1.13)
Removing json-ld (3.1.0)
Removing pghero (2.3.0)
Removing rails (5.2.4.1)
Removing aws-sdk-kms (1.24.0)
Removing actionmailer (5.2.4.1)
Removing bootsnap (1.4.4)
Removing mime-types-data (3.2019.0904)
Removing simple_form (5.0.1)
Removing httplog (1.4.1)
Removing hamlit (2.9.3)
Removing excon (0.73.0)
Removing sidekiq-unique-jobs (6.0.19)
Removing tty-cursor (0.7.0)
Removing fastimage (2.1.5)
Removing puma (4.3.1)
Removing tty-reader (0.6.0)
Removing elasticsearch-transport (7.3.0)
Removing oj (3.9.2)
Removing redis-namespace (1.6.0)
Removing actionpack (5.2.4.1)
Removing kaminari-core (1.2.0)
Removing aws-sdk-kms (1.25.0)
Removing goldfinger (2.1.0)
Removing actioncable (5.2.4.1)
Removing wisper (2.0.0)
Removing aws-sdk-kms (1.27.0)
Removing blurhash (0.1.3)
Removing fugit (1.1.6)
Removing activestorage (5.2.4.1)
Removing rdf (3.0.9)
Removing rack-attack (6.1.0)
Removing pkg-config (1.3.9)
Removing aws-sigv4 (1.1.0)
Removing pg (1.2.2)
Removing method_source (1.0.0)
Removing unf_ext (0.0.7.5)
Removing doorkeeper (5.1.0)
Removing oj (3.10.1)
Removing et-orbi (1.1.6)
Removing addressable (2.6.0)
Removing browser (2.5.3)
Removing sidekiq-unique-jobs (6.0.18)
Removing http (3.3.0)
Removing nokogiri (1.10.5)
Removing activemodel (5.2.3)
Removing tty-color (0.4.3)
Removing aws-sdk-core (3.86.0)
Removing nokogiri (1.10.8)
Removing doorkeeper (5.2.1)
Removing mime-types-data (3.2018.0812)
Removing premailer-rails (1.11.0)
Removing tzinfo (1.2.6)
Removing faraday (1.0.0)
Removing cld3 (3.2.6)
Removing sanitize (5.0.0)
Removing rack-cors (1.1.0)
Removing omniauth (1.9.0)
Removing redis-activesupport (5.2.0)
Removing responders (2.4.1)
Removing bootsnap (1.4.5)
Removing railties (5.2.3)
Removing parslet (2.0.0)
Removing pkg-config (1.3.7)
Removing httplog (1.3.2)
Removing redis-actionpack (5.2.0)
Removing rack-protection (2.0.7)
Removing loofah (2.2.3)
Removing loofah (2.3.1)
Removing redis (4.1.2)
Removing mime-types (3.3)
Removing websocket-extensions (0.1.3)
Removing actionview (5.2.3)
Removing oj (3.7.12)
Removing temple (0.8.1)
Removing strong_migrations (0.5.1)
Removing pundit (2.0.1)
Removing websocket-driver (0.7.0)
Removing actionmailer (5.2.3)
Removing aws-sdk-s3 (1.60.1)
Removing httplog (1.3.3)
Removing concurrent-ruby (1.1.5)
Removing activejob (5.2.4.1)
Removing ostatus2 (2.0.3)
Removing webpush (1.0.0)
Removing multi_json (1.13.1)
Removing activesupport (5.2.3)
Removing elasticsearch-api (6.0.2)
Removing httplog (1.3.1)
Removing json-ld-preloaded (3.0.2)
Removing active_model_serializers (0.10.9)
Removing nio4r (2.3.1)
Removing rails-html-sanitizer (1.0.4)
Removing rails-settings-cached (0.7.2)
Removing crass (1.0.4)
Removing strong_migrations (0.4.0)
Removing i18n (1.7.0)
Removing rack-attack (6.2.1)
Removing elasticsearch-api (7.3.0)
Removing ox (2.11.0)
Removing tzinfo (1.2.5)
Removing minitest (5.11.3)
Removing rufus-scheduler (3.5.2)
Removing i18n (1.6.0)
Removing aws-sdk-s3 (1.42.0)
Removing browser (3.0.3)
Removing msgpack (1.3.1)
Removing net-ldap (0.16.1)
Removing minitest (5.12.0)
Removing excon (0.62.0)
Removing webpacker (4.0.7)
Removing httplog (1.4.0)
Removing paperclip (6.1.0)
Removing et-orbi (1.2.4)
Removing rails-html-sanitizer (1.2.0)
Removing iso-639 (0.2.8)
Removing rqrcode (0.10.1)
Removing pg (1.1.4)
Removing equatable (0.5.0)
Removing sidekiq-unique-jobs (6.0.15)
Removing rqrcode_core (0.1.2)
Removing rack-attack (6.0.0)
Removing minitest (5.13.0)
Removing aws-partitions (1.207.0)
Removing pkg-config (1.4.0)
Removing rdf (3.0.12)
Removing sidekiq-unique-jobs (6.0.13)
Removing tty-screen (0.7.0)
Removing activesupport (5.2.4.1)
Removing sidekiq-unique-jobs (6.0.20)
Removing devise (4.6.2)
Removing json-ld (3.1.1)
Removing actioncable (5.2.3)
Removing css_parser (1.7.0)
Removing http-form_data (2.3.0)
Removing json-ld-preloaded (3.0.4)
Removing crass (1.0.5)
Removing simple-navigation (4.0.5)
Removing json-canonicalization (0.1.0)
Removing puma (3.12.1)
Removing browser (2.7.1)
Removing tzinfo-data (1.2019.1)
Removing stoplight (2.1.3)
Removing simple_form (4.1.0)
Removing puma (4.2.0)
Removing doorkeeper (5.2.2)
Removing oj (3.10.3)
Removing sidekiq-scheduler (3.0.0)
Removing public_suffix (3.1.0)
Removing elasticsearch-dsl (0.1.9)
Removing activemodel (5.2.4.1)
Removing charlock_holmes (0.7.6)
Removing actionpack (5.2.3)
Removing public_suffix (4.0.1)
Removing nio4r (2.5.1)
Removing railties (5.2.4.1)
Removing aws-partitions (1.175.0)
Removing aws-partitions (1.240.0)
Removing tty-color (0.5.0)
Removing aws-partitions (1.261.0)
Removing builder (3.2.3)
Removing elasticsearch-transport (6.0.2)
Removing aws-sdk-core (3.78.0)
Removing aws-sdk-kms (1.21.0)
Removing strong_migrations (0.4.2)
Removing rack-cors (1.0.3)
Removing doorkeeper (5.2.3)
Removing nokogumbo (2.0.2)
Removing sidekiq (5.2.7)
Removing aws-sdk-s3 (1.55.0)
Removing premailer-rails (1.10.2)
Removing tty-prompt (0.19.0)
Removing redis-store (1.8.2)
Removing parallel (1.17.0)
Removing tilt (2.0.9)
Removing webpacker (4.2.0)
Removing json-ld-preloaded (3.1.1)
Removing chewy (5.0.0)
Removing rdf-normalize (0.3.3)
Removing aws-sdk-core (3.55.0)
Removing json-ld (3.0.2)
Removing mimemagic (0.3.3)
Removing dotenv-rails (2.7.2)
Removing tty-command (0.8.2)
Removing multipart-post (2.0.0)
Removing actionview (5.2.4.1)
Removing browser (2.6.1)
Removing chunky_png (1.3.10)
Removing activejob (5.2.3)
Removing oj (3.9.1)
Removing aws-sdk-s3 (1.48.0)
Removing dotenv (2.7.2)
Removing nokogiri (1.10.3)
Removing cld3 (3.2.4)
Removing domain_name (0.5.20180417)
Removing pastel (0.7.2)
Removing ox (2.12.1)
Removing redis-rack (2.1.2)
Removing fog-openstack (0.3.10)
Removing faraday (0.15.0)
Removing pghero (2.2.1)
Removing activestorage (5.2.3)
Removing mini_mime (1.0.1)
Removing activerecord (5.2.3)
Removing faraday (0.15.4)
Removing hashie (3.6.0)
Removing elasticsearch (6.0.2)
Removing elasticsearch-dsl (0.1.5)
Removing strong_migrations (0.4.1)
Removing ruby-saml (1.11.0)
Removing pkg-config (1.3.8)
Removing msgpack (1.2.10)
Removing minitest (5.12.2)
Removing rack (2.1.2)
Removing kaminari (1.2.0)
Removing aws-sdk-core (3.65.1)
Removing rails (5.2.3)
Removing nokogiri (1.10.7)
Removing devise-two-factor (3.0.3)
Removing request_store (1.4.1)
Removing jsonapi-renderer (0.2.0)
Removing json-ld (e742697a0906)

mastodon@xxx:~/live$ bundle install
Using rake 13.0.1
Using concurrent-ruby 1.1.6
Using i18n 1.8.2
Using minitest 5.14.0
Using thread_safe 0.3.6
Using tzinfo 1.2.7
Using activesupport 5.2.4.2
Using builder 3.2.4
Using erubi 1.9.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.9
Using rails-dom-testing 2.0.3
Using crass 1.0.6
Using loofah 2.4.0
Using rails-html-sanitizer 1.3.0
Using actionview 5.2.4.2
Using rack 2.2.2
Using rack-test 1.1.0
Using actionpack 5.2.4.2
Using nio4r 2.5.2
Using websocket-extensions 0.1.4
Using websocket-driver 0.7.1
Using actioncable 5.2.4.2
Using globalid 0.4.2
Using activejob 5.2.4.2
Using mini_mime 1.0.2
Using mail 2.7.1
Using actionmailer 5.2.4.2
Using activemodel 5.2.4.2
Using case_transform 0.2
Using jsonapi-renderer 0.2.2
Using active_model_serializers 0.10.10
Using arel 9.0.0
Using activerecord 5.2.4.2
Using mimemagic 0.3.4
Using marcel 0.3.3
Using activestorage 5.2.4.2
Using public_suffix 4.0.3
Using addressable 2.7.0
Using encryptor 3.0.0
Using attr_encrypted 3.1.0
Using climate_control 0.2.0
Using cocaine 0.5.8
Using av 0.9.0
Using aws-eventstream 1.0.3
Using aws-partitions 1.286.0
Using aws-sigv4 1.1.1
Using jmespath 1.4.0
Using aws-sdk-core 3.92.0
Using aws-sdk-kms 1.30.0
Using aws-sdk-s3 1.61.1
Using bcrypt 3.1.12
Using ffi 1.10.0
Using blurhash 0.1.4
Using msgpack 1.3.3
Using bootsnap 1.4.6
Using browser 4.0.0
Using bundler 2.1.4
Using charlock_holmes 0.7.7
Using multi_json 1.14.1
Using elasticsearch-api 7.5.0
Using multipart-post 2.1.1
Using faraday 0.17.3
Using elasticsearch-transport 7.5.0
Using elasticsearch 7.5.0
Using elasticsearch-dsl 0.1.8
Using chewy 5.1.0
Using chunky_png 1.3.11
Using cld3 3.3.0
Using connection_pool 2.2.2
Using css_parser 1.7.1
Using orm_adapter 0.5.0
Using method_source 0.9.2
Using thor 0.20.3
Using railties 5.2.4.2
Using responders 3.0.0
Using warden 1.2.8
Using devise 4.7.1
Using rotp 2.1.2
Using devise-two-factor 3.1.0
Using discard 1.2.0
Using unf_ext 0.0.7.6
Using unf 0.1.4
Using domain_name 0.5.20190701
Using doorkeeper 5.3.1
Using dotenv 2.7.5
Using dotenv-rails 2.7.5
Using e2mmap 0.1.0
Using equatable 0.6.1
Using et-orbi 1.2.3
Using excon 0.71.0
Using fast_blank 1.0.0
Using fastimage 2.1.7
Using ffi-compiler 1.0.1
Using formatador 0.2.5
Using mime-types-data 3.2019.1009
Using mime-types 3.3.1
Using fog-core 2.1.0
Using fog-json 1.2.0
Using ipaddress 0.8.3
Using fog-openstack 0.3.7
Using raabro 1.1.6
Using fugit 1.3.3
Using http-cookie 1.0.3
Using http-form_data 2.2.0
Using http-parser 1.2.1
Using http 4.3.0
Using oj 3.10.5
Using goldfinger 2.1.1
Using temple 0.8.2
Using tilt 2.0.10
Using hamlit 2.11.0
Using hamlit-rails 0.2.3
Using hamster 3.0.0
Using hashie 4.1.0
Using sprockets 3.7.2
Using sprockets-rails 3.2.1
Using rails 5.2.4.2
Using health_check 4.0.0.pre from https://github.com/ianheggie/health_check (at 0b799ea@0b799ea)
Using hiredis 0.6.3
Using hkdf 0.3.0
Using htmlentities 4.3.4
Using http_accept_language 2.1.1
Using http_parser.rb 0.6.1 from https://github.com/tmm1/http_parser.rb (at 54b17ba@54b17ba)
Using rainbow 3.0.0
Using httplog 1.4.2
Using idn-ruby 0.1.0
Using iso-639 0.3.5
Using json-canonicalization 0.2.0
Using link_header 0.0.8
Using rdf 3.1.1
Using json-ld 3.1.2
Using json-ld-preloaded 3.1.2
Using jwt 2.1.0
Using kaminari-core 1.1.1
Using kaminari-actionview 1.1.1
Using kaminari-activerecord 1.1.1
Using kaminari 1.1.1
Using request_store 1.5.0
Using lograge 0.11.2
Using makara 0.4.1
Using redis 4.1.3
Using mario-redis-lock 1.2.1
Using necromancer 0.5.1
Using net-ldap 0.16.2
Using nilsimsa 1.1.2 from https://github.com/witgo/nilsimsa (at fd18488@fd18488)
Using nokogumbo 2.0.1
Using rack-protection 2.0.8.1
Using sidekiq 6.0.4
Using statsd-ruby 1.4.0
Using nsa 0.2.7
Using omniauth 1.9.1
Using omniauth-cas 1.1.1
Using ruby-saml 1.9.0
Using omniauth-saml 1.10.1
Using ox 2.13.2
Using terrapin 0.6.0
Using paperclip 6.0.0
Using paperclip-av-transcoder 0.6.4
Using parallel 1.19.1
Using parslet 1.8.2
Using tty-color 0.5.1
Using pastel 0.7.3
Using pg 1.2.3
Using pghero 2.4.1
Using pkg-config 1.4.1
Using posix-spawn 0.3.13 from https://github.com/rtomayko/posix-spawn (at 58465d2@58465d2)
Using premailer 1.11.1
Using premailer-rails 1.10.3
Using private_address_check 0.5.0
Using puma 4.3.3
Using pundit 2.1.0
Using rack-attack 6.2.2
Using rack-cors 1.1.1
Using rack-proxy 0.6.5
Using rails-i18n 5.1.3
Using rails-settings-cached 0.6.6
Using rdf-normalize 0.4.0
Using redis-store 1.5.0
Using redis-rack 2.0.4
Using redis-actionpack 5.0.2
Using redis-activesupport 5.0.4
Using redis-namespace 1.7.0
Using redis-rails 5.0.2
Using rqrcode_core 0.1.1
Using rqrcode 1.1.2
Using ruby-progressbar 1.10.1
Using rufus-scheduler 3.6.0
Using sanitize 5.1.0
Using sidekiq-bulk 0.2.0
Using thwait 0.1.0
Using sidekiq-scheduler 3.0.1
Using sidekiq-unique-jobs 6.0.21
Using simple-navigation 4.1.0
Using simple_form 5.0.2
Using stoplight 2.2.0
Using streamio-ffmpeg 3.0.2
Using strong_migrations 0.6.2
Using tty-command 0.9.0
Using tty-cursor 0.7.1
Using tty-screen 0.7.1
Using wisper 2.0.1
Using tty-reader 0.7.0
Using tty-prompt 0.21.0
Using twitter-text 1.14.7
Using tzinfo-data 1.2019.3
Using webpacker 4.2.2
Using webpush 0.3.8
Bundle complete! 126 Gemfile dependencies, 208 gems now installed.
Gems in the groups development and test were not installed.
Bundled gems are installed into `./vendor/bundle`
```
直ったっぽい。


その他、森野 くますん様の[Mastodon 保守メモ](https://qiita.com/kumasun/items/bf4997f181f893130041)めっちゃ助かってます。多謝です。

Mastodonのアップデート
http://imoimo2010.blogspot.jp/2017/05/mastodon_34.html
ほぼほぼ上記の方法でアップデートできるはず。

Mastodonマストドンのアップデート方法メモ
https://www.webdb.co.jp/~atsumi/skimemo/index.php?skimemo%20-%20%C6%FC%B5%AD%2F2017-04-20%2FMastodon%A5%DE%A5%B9%A5%C8%A5%C9%A5%F3%A4%CE%A5%A2%A5%C3%A5%D7%A5%C7%A1%BC%A5%C8%CA%FD%CB%A1%A5%E1%A5%E2
ちょっと気になった時に

[備忘録]Mastodonアップデートの時のメモと注意
http://qiita.com/plainbanana/items/8cecc9c0b6805559b157
gitコマンドの場合

アップデートした後
Mastodon のデイリーJOBが異常終了する解消方法
http://fnya.cocolog-nifty.com/blog/2017/04/mastodon-job-13.html
これをしないと(bundle exec)rake mastodon:dailyが出来ない場合がある。

db:migradeの前に
RAILS_ENV=production bundle exec rails mastodon:maintenance:prepare_for_foreign_keys
v1.4.7→v1.5.0rc1
RAILS_ENV=production bundle exec rake mastodon:webpush:generate_vapid_key