2

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

使用 USR2 重启 Unicorn 似乎不会重新加载 production.rb 设置

但是,我的 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。

4

1 回答 1

6

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

于 2012-06-26T00:29:38.673 回答