5
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?