about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-02-23 16:10:02 -0800
committerEric Wong <normalperson@yhbt.net>2009-02-23 16:13:12 -0800
commitecbff236982f0ac94555171f86cee217929a978a (patch)
tree3a4969a40a78def0f827e597539544abb28c409f /lib
parent8f98c7d125e817d1175ba359375baddf28db4b7b (diff)
downloadunicorn-ecbff236982f0ac94555171f86cee217929a978a.tar.gz
This allows Unicorn to be constantly started in symlink
paths such as the ones Capistrano creates
(e.g. "/u/apps/$app/current")
Diffstat (limited to 'lib')
-rw-r--r--lib/unicorn.rb9
-rw-r--r--lib/unicorn/configurator.rb5
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index 5b12fc8..aad4c3d 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -125,6 +125,13 @@ module Unicorn
       @pid = path
     end
 
+    # sets the path for running the master and worker process, useful for
+    # running and reexecuting from a symlinked path like Capistrano allows
+    def directory=(path)
+      Dir.chdir(path) if path
+      @directory = path
+    end
+
     # add a given address to the +listeners+ set, idempotently
     # Allows workers to add a private, per-process listener via the
     # @after_fork hook.  Very useful for debugging and testing.
@@ -316,7 +323,7 @@ module Unicorn
         ENV.replace(@start_ctx[:environ])
         ENV['UNICORN_FD'] = @listeners.map { |sock| sock.fileno }.join(',')
         File.umask(@start_ctx[:umask])
-        Dir.chdir(@start_ctx[:cwd])
+        Dir.chdir(@cwd || @start_ctx[:cwd])
         cmd = [ @start_ctx[:zero] ] + @start_ctx[:argv]
         logger.info "executing #{cmd.inspect} (in #{Dir.pwd})"
         exec(*cmd)
diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb
index 9457480..ebdcba6 100644
--- a/lib/unicorn/configurator.rb
+++ b/lib/unicorn/configurator.rb
@@ -20,6 +20,7 @@ module Unicorn
       :before_fork => lambda { |server, worker_nr|
           server.logger.info("worker=#{worker_nr} spawning...")
         },
+      :directory => nil,
       :pid => nil,
       :backlog => 1024,
     }
@@ -137,6 +138,10 @@ module Unicorn
       @set[:pid] = path
     end
 
+    def directory(path)
+      @set[:directory] = path ? File.expand_path(path) : nil
+    end
+
     private
 
     def set_hook(var, my_proc) #:nodoc: