Unicorn在旧版本目录中重新启动

时间:2012-06-25 23:26:34

标签: ruby-on-rails rvm capistrano unicorn

我有一个似乎工作正常的capistrano部署,但是在将USR2信号发送到unicorn进程后,它会在旧版本文件夹中重新启动。它有点类似于这里的问题:

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

但是,我的working_directory设置为一个字符串,我对它没有任何兴趣。

我的制作独角兽配置:

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

我的capistrano部署:

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" 

我不知道在哪里看。如果服务器完全停止然后重新启动它将使用正确的文件夹,但使用USR2信号它将不会使用符号链接中的正确路径。就像它在加载配置时解析符号链接而在代码重新启动之前不再解析它。

我正在使用RVM。

1 个答案:

答案 0 :(得分:6)

在我的一个Rake任务中引用了“Rails.root”导致符号链接解析。用对共享目录的硬编码引用替换它,并且它有效。