独角兽在旧发行目录中重新启动

问题描述 投票:2回答:1

我有一个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。

ruby-on-rails rvm capistrano unicorn
1个回答
6
投票

在我的Rake任务之一中引用了“ Rails.root”,这导致符号链接得以解决。 将其替换为对共享目录的硬编码引用,即可正常工作。


推荐问答