【问题标题】:Unicorn restarting in old release directory独角兽在旧版本目录中重新启动
【发布时间】:2012-06-25 23:26:34
【问题描述】:

我有一个似乎工作正常的 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。

【问题讨论】:

    标签: ruby-on-rails rvm capistrano unicorn


    【解决方案1】:

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

    【讨论】:

    • 考虑选择这个作为答案,这样它就会出现在已解决的类别中!
    猜你喜欢
    • 2011-12-24
    • 2013-10-21
    • 1970-01-01
    • 2012-06-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多