7

unicorn でのホット デプロイに問題があります。正規の構成をほとんど使用し、シンボリックリンクされたフォルダーを指すようunicorn.rbに設定しworking_directoryますが、最初に起動したときに実際のフォルダーに固執しているように見え、シンボリックリンクをたどることができません。

# config/unicorn.rb
if ENV['RAILS_ENV'] == 'production'
  worker_processes 4
else
  worker_processes 2
end

working_directory "/var/local/project/symlinkfolder"

# Listen on unix socket
listen "/tmp/unicorn.sock", :backlog => 64

pid "/var/run/unicorn/unicorn.pid"

stderr_path "/var/log/unicorn/unicorn.log"
stdout_path "/var/log/unicorn/unicorn.log"

preload_app true

before_fork do |server, worker|
  # the following is highly recomended for Rails + "preload_app true"
  # as there's no need for the master process to hold a connection
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
  end

  # Before forking, kill the master process that belongs to the .oldbin PID.
  # This enables 0 downtime deploys.
  old_pid = "/var/run/unicorn/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|
  # the following is *required* for Rails + "preload_app true",
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
  end

  # this makes sure the logging-rails framework works when preload_app = true
  Logging.reopen
  # if preload_app is true, then you may also want to check and
  # restart any other shared sockets/descriptors such as Memcached,
  # and Redis.  TokyoCabinet file handles are safe to reuse
  # between any number of forked children (assuming your kernel
  # correctly implements pread()/pwrite() system calls)
end  

を発行するUSR2と、ユニコーン ログに次のように表示されます。

executing ["/var/local/project/project.d/6/vendor/bundle/ruby/1.9.1/bin/unicorn_rails", "-E", "staging", "-D", "-c", "/var/local/project/symlinkfolder/config/unicorn.rb"│·
, {12=>#<Kgio::UNIXServer:fd 12>}] (in /var/local/project/project.d/8)

そのため、ユニコーンは何らかの形でバージョン 6 に「スタック」していますが、実際のシンボリックリンクされたフォルダーはバージョン 8 にあります...これは、いくつかのデプロイ後にバージョン 6 のフォルダーを整理するとすぐに問題になります...

  • シンボリックリンクされたworking_directoryフォルダーに設定されます
  • /var/local/project/project.d/[id]シンボリックリンクはフォルダーを正しく指しています
  • シグナルを送信するにシンボリックリンクを更新しますUSR2

私たちは何を見逃しましたか??

4

1 に答える 1

8

解決策は、ユニコーンのバイナリ パスを明示的に設定することでした

app_root = "/var/local/project/symlinkfolder"
working_directory app_root
# see http://unicorn.bogomips.org/Sandbox.html
Unicorn::HttpServer::START_CTX[0] = "#{app_root}/vendor/bundle/ruby/1.9.1/bin/unicorn_rails"

unicorn reload次に、 ( kill -HUP) コマンドを発行する必要があったため、unicorn は構成ファイルをリロードします。そして、それ以降、USR2シグナルの発行は正常に機能します。

于 2013-02-25T16:10:46.583 に答える