LoginSignup
5
8

More than 5 years have passed since last update.

Rails + Capistrano + Unicorn である日 Gemfileが読み込めなくなった話

Posted at

Railsアプリを Capistrano + Unicorn + nginxでデプロイができるようになって喜んでいたのですが
ある日いつもの bundle exec cap production deployは成功するが結果が反映されなくなった、、、

unicorn.log
I, [2017-06-18T07:25:00.381245 #18202]  INFO -- : executing ["/var/www/myapp/shared/bundle/ruby/2.4.0/bin/unicorn", "-c", "/var/www/myapp/current/config/unicorn/production.rb", "-E", "production", "-D", {11=>#<Kgio::UNIXServer:fd 11>}] (in /var/www/myapp/releases/20170618072435)
I, [2017-06-18T07:25:00.381795 #18202]  INFO -- : forked child re-executing...
/home/suppin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/definition.rb:31:in `build': /var/www/myapp/releases/20170606053023/Gemfile not found (Bundler::GemfileNotFound)

エラーを見に行ったところGemfileがないと言われていました・・・

解決方法

myapp/config/unicorn/production.rb に下記を追記してあげる。
(環境によってはパスが異なるかもしれません)

production.rb
before_exec do |server|
  ENV["BUNDLE_GEMFILE"] = File.join(File.expand_path("../../../../", __FILE__), "current", "Gemfile")
end

その後unicornを再起動

補足

capistranoを使っていて、いつものkill -9コマンドでpidを殺しにいくと自動デプロイするときに怒られる。なのでcurrent/tmp/pid/unicorn.pidとかのファイルを削除してあげる必要がある。

解決方法は
http://unlearned.hatenablog.com/entry/2014/03/10/230954
を参考にさせていただきました。ありがとうございます。

5
8
1

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
5
8