LoginSignup
6
3

More than 3 years have passed since last update.

bundle exec cap production deployで生じた6つのエラーの解決法

Posted at
$ bundle exec cap production deploy

上記のコマンドで自動デプロイしようとしたときに発生したエラーとその解決法をまとめました。

もし自分が今詰まっているエラーと同じエラーがあり、何らかの参考になれば幸いです。

エラー①〜⑤はエラー文をそのままググって解決法を見つけました。
エラー⑥は$ less log/unicorn.logでunicornのエラーログを見に行かないと気付けませんでした。

後から振り返ると、ただエラー文でググるだけじゃなくて、最初からエラーログを確認するコマンドでエラーログを確認しに行っていれば、もっと早く解決できたんじゃないかなと思いました。

エラー① SSHKit::Runner::ExecuteError: Exception while executing as ec2-user@ElasticIP: Authentication failed for user ec2-user@ElasticIP

(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ec2-user@ElasticIP: Authentication failed for user ec2-user@ElasticIP

解決法

config/deploy/production.rb
#デプロイするサーバーにsshログインする鍵の情報を記述
set :ssh_options, keys: '~/.ssh/ssh鍵の名前'

ssh鍵の名前が間違っていました。

username@aaaa-MacBook-Air-6 .ssh % ssh ssh鍵の名前

EC2に入るときに使うssh鍵の名前に変更したら解決しました。

エラー② NotImplementedError: OpenSSH keys only supported if ED25519 is available

net-ssh requires the following gems for ed25519 support:

NotImplementedError: OpenSSH keys only supported if ED25519 is available
net-ssh requires the following gems for ed25519 support:
* ed25519 (>= 1.2, < 2.0)
* bcrypt_pbkdf (>= 1.0, < 2.0)
See https://github.com/net-ssh/net-ssh/issues/565 for more information
Gem::LoadError : "ed25519 is not part of the bundle. Add it to your Gemfile."

「なんだこのエラーは?」と思いましたが、2つのgemを$ bundle installしたら無事解決しました。

解決法

Gemfile
gem 'ed25519'
gem 'bcrypt_pbkdf'

Gemfileにこれらを追加してbundle installしたら解決しました。

エラー③ ERROR linked file /var/www/アプリケーション名/shared/config/settings.yml does not exist on ElasticIP

deploy:check:linked_files
ERROR linked file /var/www/アプリケーション名/shared/config/settings.yml does not exist on ElasticIP

解決法

config/deploy.rb
# before
set :linked_files, fetch(:linked_files, []).push('config/settings.yml')

# after
# set :linked_files, fetch(:linked_files, []).push('config/settings.yml')

これは今でもよくわかっていないのですが、このシンボリックファイルの部分をコメントアウトしたら解決しました。

シンボリックファイルとは、公開されてしまうとまずいデータが入っているファイルの仮のファイルを作ってくれる(合ってる?)ようなのですが、必ずしも必要というわけではないんでしょうか?

※今調べているところでして、わかったら追記します🙇‍♂️

エラー④ The deploy has failed with an error: Don't know how to build task

The deploy has failed with an error: Don't know how to build task 'unicorn:restart' (See the list of available tasks with `cap --tasks`)

unicornの再起動の設定が間違っていたようです。

config/deploy.rbの設定を変えたらうまくいったのですが、いくつかの記事を見てみたところ、deploy.rbの設定も記事によって微妙に違っていて、どれが正しいのか全部正しいのかわからず、モヤモヤしました😅

解決法

config/deploy.rb
# before
  desc 'Restart application'
  task :restart do
    invoke 'unicorn:restart'
  end

# after
  desc 'Restart application'
  task :restart do
    on roles(:app) do
      invoke 'unicorn:restart'
    end
  end

エラー⑤ SSHKit::Runner::ExecuteError: Exception while executing as naota@ElasticIP: Don't know how to build task 'unicorn:restart'

SSHKit::Runner::ExecuteError: Exception while executing as naota@ElasticIP: Don't know how to build task 'unicorn:restart' (See the list of available tasks with `cap --tasks`)

capistrano3-unicornというgemを使うやり方と使わないやり方とどっちもあって、必ずしも必要というわけではないみたいですが、今回はこれを導入しただけで解決しました。

解決法

https://github.com/tablexi/capistrano3-unicorn
にしたがってcapistrano3-unicornを導入。

リンク先のSetupという章にしたがって進めていけばできます。

エラー⑥ kill stderr: cat: /var/www/pfc-master/current/tmp/pids/unicorn.pid: No such file or directory

Exception while executing as naota@ElasticIp: kill exit status: 1 (SSHKit::Runner::ExecuteError)
kill stdout: Nothing written
kill stderr: cat: /var/www/pfc-master/current/tmp/pids/unicorn.pid: No such file or directory
kill: 十分な引数がありません

解決法

config/unicorn/production.rb
# 修正前
$app_dir = "/var/www/rails/pfc-master" 
# 修正後
$app_dir = "/var/www/pfc-master/current"

これがいちばん苦労しました。
本番環境のunicornの設定をするファイル(たぶん?)config/unicorn/production.rbの中の$app_dirのpathの設定が間違っていました。

kill stderr: cat: /var/www/pfc-master/current/tmp/pids/unicorn.pid: No such file or directory

unicornのプロセスを記録するファイルの配置が違っていたために、unicornのプロセスがkillできず、その結果unicornの再起動ができなくなっているのが原因でした。

ここに気づくまでにめちゃくちゃいろいろ遠回りして時間かかりました😅

このエラー解決だけまた別で記事書こうかなと思います。

今回は各エラーとその解決法を並べただけですが、1つ1つちゃんと理解できているかというと、結果的に解決したもののちゃんと理解できていないところも結構あるので、そこはしっかり調べて追記するなり別の記事で書いていければと思います。

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3