2

I have a capistrano deployment that seems to be working fine, however after the USR2 signal is sent to the unicorn process it restarts in the old release folder. It is somewhat similar to the problem here:

Restarting Unicorn with USR2 doesn't seem to reload production.rb settings

However, my working_directory is set to a string, I'm not doing anything fancy with it.

My production unicorn config:

worker_processes 4
working_directory "/u/apps/dragonfly-application/current" # available in 0.94.0+
listen "/tmp/.sock", :backlog => 64
timeout 30
pid "/u/apps/dragonfly-application/shared/pids/unicorn.pid"
stderr_path "/u/apps/dragonfly-application/shared/log/unicorn.stderr.log"
stdout_path "/u/apps/dragonfly-application/shared/log/unicorn.stdout.log"

preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
  GC.copy_on_write_friendly = true

before_fork do |server, worker|
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!

    old_pid = '/u/apps/dragonfly-application/shared/pids/unicorn.pid.oldbin'
      if File.exists?(old_pid) && server.pid != old_pid
        begin
          Process.kill("QUIT", File.read(old_pid).to_i)
        rescue Errno::ENOENT, Errno::ESRCH
          # someone else did our job for us
        end
      end

end

after_fork do |server, worker|
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

And my capistrano deployment:

set :application, "dragonfly-application"
set :repository, "git@github.com:Rodeoclash/Nile.git"
set :scm, :git
set :user, "user"
set :rvm_ruby_string, "1.9.3@dragonfly-application"
set :bundle_flags, "--deployment --binstubs"

server "202.2.94.221", :app, :web, :db, :primary => true

before 'deploy:setup', 'rvm:install_rvm'
before 'deploy:setup', 'rvm:install_ruby'

after "deploy:finalize_update", "db:config"
after "deploy:restart", "deploy:cleanup" # clean up old releases on each deploy
after "deploy", "deploy:migrate"
after 'deploy:update_code', 'symlink_uploads'

load 'deploy/assets'

namespace :db do

  # copy database.yml into location
  task :config, :except => { :no_release => true }, :role => :app do
    run "cp -f #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end

  desc "reload the database with seed data"
  task :seed do
    run "cd #{current_path}; bundle exec rake db:seed RAILS_ENV=#{rails_env}"
  end

end

task :symlink_uploads do
    run "ln -nfs #{shared_path}/uploads  #{release_path}/public/uploads"
end

require "bundler/capistrano"
require 'capistrano-unicorn'
require "rvm/capistrano" 

I'm out of ideas of where to look. If the server is totally stopped then restarted it will use the correct folder, but using the USR2 signal it will not use the correct path in the symlink. It's like it's resolving the symlink when loading the config and not resolving it again until the code has restarted.

I'm using RVM.

Community
  • 1
  • 1
Samuel
  • 2,331
  • 1
  • 22
  • 40

1 Answers1

6

Had a reference to "Rails.root" in one of my Rake tasks which was causing the symlink to resolve. Replaced that with a hardcoded reference to the shared directory and it worked.

Samuel
  • 2,331
  • 1
  • 22
  • 40