3
votes

The app deploys fine if I want to tolerate downtime from manually stopping and starting unicorn after a deployment. However, I want to use the zero-downtime unicorn settings, but it isn't working because the new unicorn process that starts up is looking at the old deployment release path. Nothing special, simple cap restart in deploy.rb:

desc "Zero-downtime restart of Unicorn"
    task :restart, :except => { :no_release => true } do
        run "cd #{current_path}; #{try_sudo} kill -s USR2 `cat /var/www/appname/shared/pids/unicorn.pid`"
    end

I know that it's looking at the wrong directory because if the views don't change, and if I set keep_releases to 1 or 2, the unicorn logs will show an error because the directory it's trying to start up in was deleted:

/var/www/appname/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:425:in `chdir': No such file or directory - /var/www/appname/releases/20130330104246 (Errno::ENOENT)

I've been trying to debug this on and off for several weeks now. Any help getting this working is greatly appreciated!

1

1 Answers

6
votes

Set this environment variable when starting unicorn

BUNDLE_GEMFILE=$APP_PATH/current/Gemfile

Otherwise it will point at a specific release directory, which will cause the behaviour you describe.

eg.

cd $APP_PATH/current && BUNDLE_GEMFILE=$APP_PATH/current/Gemfile bundle exec unicorn_rails -c $APP_PATH/current/config/unicorn.rb -E $RAILS_ENV -D