LoginSignup
35
26

More than 5 years have passed since last update.

Capstarano3でデプロイ時にUnicornが再起動しているようで失敗している時の対処法

Posted at

Capstarano3 + Unicornでデプロイしている時、capコマンドで実行するとUnicornの再起動ログがSuccessになっているのにもかかわらず、サーバのUnicornプロセスを確認すると、どうも再起動されていない…。という現象にぶち当たり、色々調べると成功しているように見せかけて、実は失敗していたっていうお話。

Unicornが再起動されたかの確認

paコマンドでいつ起動されたかの確認

command
$ ps -eo lstart,pid,args | grep uni

Mon Nov 10 13:48:14 2014 17039 unicorn master -c /var/www/app/current/config/unicorn/staging.rb -E staging -D
Mon Nov 10 13:48:18 2014 17083 unicorn worker[0] -c /var/www/app/current/config/unicorn/staging.rb -E staging -D
Mon Nov 10 13:52:22 2014 17087 grep uni

psコマンドでいつ起動されたかを確認。この時点で、過去の日付だと明らかに再起動されていない。

Unicornのエラーログで確認

command
$ tail -f /var/www/app/log/unicorn.stderr.log

I, [2014-11-10T13:39:28.817252 #14552]  INFO -- : executing ["/var/www/app/shared/bundle/ruby/2.1.0/bin/unicorn", "-c", "/var/www/app/current/config/unicorn/staging.rb", "-E", "staging", "-D", {11=>#<Kgio::UNIXServer:fd 11>}] (in /var/www/app/releases/20141110043913)
I, [2014-11-10T13:39:28.817497 #14552]  INFO -- : forked child re-executing...
/home/ec2-user/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/definition.rb:22:in `build': /var/www/app/releases/20141107020905/Gemfile not found (Bundler::GemfileNotFound)
        from /home/ec2-user/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler.rb:154:in `definition'
        from /home/ec2-user/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler.rb:117:in `setup'
        from /home/ec2-user/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/setup.rb:17:in `<top (required)>'
        from /home/ec2-user/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/ec2-user/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
E, [2014-11-10T13:39:28.995313 #3233] ERROR -- : reaped #<Process::Status: pid 14552 exit 1> exec()-ed

Gemfile not found (Bundler::GemfileNotFound)というエラーが出ている。

Gemfileの場所を明示して対応する

config/unicorn/staging.rb
before_exec do |server|
  ENV['BUNDLE_GEMFILE'] = @app_path + "/current/Gemfile"
end

unicorn.rbなどの設定ファイルで、環境変数ENV['BUNDLE_GEMFILE']にGemfileの場所を明示してあげることで解消する。

すでに上記問題でデプロイ失敗している場合は注意!

すでにデプロイ失敗している環境の場合は、ENV['BUNDLE_GEMFILE']を明示して再度デプロイしても失敗してしまう。ここは、一度手動でUnicornを停止もしくは再起動させることで、問題が解消される。

35
26
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
35
26