Rostamizadeh.Blog

A place for me to write about interesting technology topics.

Capistrano Deployment Ending in Bundler::GemfileNotFound

I recently made a gemfile change, committed and pushed my changes, and ran a Capistrano deployment…which exploded in an enormous ball of fire on the server. Here’s what I saw in my deployment output:

1
2
3
4
** [out :: IP] Original PID:  21444
** [out :: IP] USR2 sent; Waiting for .oldbin
** [out :: IP] .
** [out :: IP] .

… “Throw more dots, more dots, more dots, come on more dots. Ok, stop dots.” (Congrats if you get that reference.) …

1
2
3
4
5
** [out :: IP] .
** [out :: IP] .
** [out :: IP] Waiting for new pid file
** [out :: IP] 
** [out :: IP] New master failed to start; see error log

Following the sage recommendation to view the error log, shown above, I opened my Unicorn error log and was greeted with this:

1
2
3
INFO -- : executing ["/path/to/site/shared/bundle/ruby/1.9.1/bin/unicorn", "-D", "-c", "/path/to/site/shared/config/unicorn.rb", "-E", "staging", {7=>#<Kgio::UNIXServer:fd 7>}] (in /path/to/site/releases/20120521061632)
INFO -- : forked child re-executing...
/home/{user name}/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/bundler-1.1.4/lib/bundler/definition.rb:15:in `build': /path/to/site/releases/20120520044313/Gemfile not found (Bundler::GemfileNotFound)

Technology

  • Bundler 1.1.4
  • Capistrano 2.12.0

Solution

It took me a minute of staring at the error to realize that Unicorn was starting from a newer release folder than the one Bundler was complaining about (if you didn’t notice that, look closely at the Unicorn log above and you’ll see it). What made this error more interesting was the fact that part of my Capistrano deployment includes removing old releases, and the path bundler was referencing didn’t exist anymore. Yowzer!

I figured it was time to go back and read the Unicorn Sandbox Documentation…and I’m glad I did. It turns out that when you’re using Capistrano, you need to explicitly set the path to the correct gemfile in the Unicorn.conf. My Unicorn deployment template for this file is Unicorn.rb.erb, and my fix looks like this:

1
2
3
before_exec do |server|
  ENV['BUNDLE_GEMFILE'] = "<%= current_path %>/Gemfile"
end

If you aren’t using erb, you’ll need to change <%= current_path %> to whatever is appropriate for your deployment configuration.

Comments