2013-02-21 5 views
6

Wir haben Probleme, Hot-Deployment mit Einhorn. Wir verwenden die kanonische unicorn.rb Konfiguration, stellen die working_directory so ein, dass sie auf den symlink'd-Ordner zeigt, aber irgendwie scheint es beim ersten Start im aktuellen Ordner hängen geblieben zu sein und dem Symlink nicht zu folgen.Einhorn working_directory mit Symlink

# 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 

Wenn wir ein USR2 ausstellen, sehen wir dies in dem Einhorn Protokoll:

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) 

so Einhorn irgendwie 'stecken' auf Version 6, während die tatsächlichen Symlink-Ordner auf Version 8 sind .. . dies wird zu einem Problem, sobald wir Ordner für Version 6 nach einigen entfaltet ...

  • Die working_directory ist auf den symlink'd fol beschneiden Der
  • der Symlink auf /var/local/project/project.d/[id] Ordner
  • Wir korrekt den Symlink aktualisieren vor Senden des USR2 Signal

Was wir vermissen ??

Antwort

7

Die Lösung bestand darin, das Einhorn binären Pfad explizit festgelegt, wie (in etwas verwirrend Weise) auf http://unicorn.bogomips.org/Sandbox.html erklärt

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" 

Dann eine unicorn reload (kill -HUP) Befehl zu erteilen wir brauchten so Einhorn Reloads die Konfigurationsdatei . Und von da an funktioniert die Ausgabe eines Signals USR2 ordnungsgemäß.