about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-02-25 15:05:14 -0800
committerEric Wong <normalperson@yhbt.net>2010-02-25 17:04:33 -0800
commit4b4ac5ed5d62cab76790661ba92a9ac4d5f1c105 (patch)
treebaef9d0ee6ab556f47db935222a603d345507c30
parent036df6c373df6d7f52005fbbd3196646934329d3 (diff)
downloadunicorn-4b4ac5ed5d62cab76790661ba92a9ac4d5f1c105.tar.gz
The temporary paths we create to mimic script/server-emulation
did not work when working_directory was used.  Now we defer
path creation until after working_directory is bound.
-rwxr-xr-xbin/unicorn_rails7
-rw-r--r--lib/unicorn/configurator.rb9
-rw-r--r--test/rails/test_rails.rb6
3 files changed, 14 insertions, 8 deletions
diff --git a/bin/unicorn_rails b/bin/unicorn_rails
index b327054..5204145 100755
--- a/bin/unicorn_rails
+++ b/bin/unicorn_rails
@@ -4,7 +4,6 @@ require 'unicorn/launcher'
 require 'optparse'
 require 'fileutils'
 
-rails_pid = "#{Unicorn::HttpServer::START_CTX[:cwd]}/tmp/pids/unicorn.pid"
 cmd = File.basename($0)
 daemonize = false
 listeners = []
@@ -198,12 +197,12 @@ if $DEBUG
 end
 
 # ensure Rails standard tmp paths exist
-%w(cache pids sessions sockets).each do |dir|
-  FileUtils.mkdir_p("tmp/#{dir}")
+options[:after_reload] = lambda do
+  FileUtils.mkdir_p(%w(cache pids sessions sockets).map! { |d| "tmp/#{d}" })
 end
 
 if daemonize
-  options[:pid] = rails_pid
+  options[:pid] = "tmp/pids/unicorn.pid"
   Unicorn::Launcher.daemonize!(options)
 end
 Unicorn.run(app, options)
diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb
index f6d13ab..b586c67 100644
--- a/lib/unicorn/configurator.rb
+++ b/lib/unicorn/configurator.rb
@@ -10,7 +10,7 @@ module Unicorn
   # See http://unicorn.bogomips.org/examples/unicorn.conf.rb for an
   # example config file.  An example config file for use with nginx is
   # also available at http://unicorn.bogomips.org/examples/nginx.conf
-  class Configurator < Struct.new(:set, :config_file)
+  class Configurator < Struct.new(:set, :config_file, :after_reload)
 
     # Default settings for Unicorn
     DEFAULTS = {
@@ -34,6 +34,10 @@ module Unicorn
       self.set = Hash.new(:unset)
       use_defaults = defaults.delete(:use_defaults)
       self.config_file = defaults.delete(:config_file)
+
+      # after_reload is only used by unicorn_rails, unsupported otherwise
+      self.after_reload = defaults.delete(:after_reload)
+
       set.merge!(DEFAULTS) if use_defaults
       defaults.each { |key, value| self.send(key, value) }
       Hash === set[:listener_opts] or
@@ -53,6 +57,9 @@ module Unicorn
         test(?w, path) || test(?w, File.dirname(path)) or \
               raise ArgumentError, "directory for #{var}=#{path} not writable"
       end
+
+      # unicorn_rails creates dirs here after working_directory is bound
+      after_reload.call if after_reload
     end
 
     def commit!(server, options = {}) #:nodoc:
diff --git a/test/rails/test_rails.rb b/test/rails/test_rails.rb
index 9502dcb..304f519 100644
--- a/test/rails/test_rails.rb
+++ b/test/rails/test_rails.rb
@@ -92,9 +92,6 @@ logger Logger.new('#{COMMON_TMP.path}')
     redirect_test_io { @pid = fork { exec 'unicorn_rails', "-l#@addr:#@port" } }
     wait_master_ready("test_stderr.#$$.log")
 
-    # temp dirs exist
-    tmp_dirs.each { |dir| assert(File.directory?("tmp/#{dir}")) }
-
     # basic GET
     res = Net::HTTP.get_response(URI.parse("http://#@addr:#@port/foo"))
     assert_equal "FOO\n", res.body
@@ -102,6 +99,9 @@ logger Logger.new('#{COMMON_TMP.path}')
     assert_equal "4", res['Content-Length']
     assert_equal "200 OK", res['Status']
 
+    # temp dirs exist
+    tmp_dirs.each { |dir| assert(File.directory?("tmp/#{dir}")) }
+
     # can we set cookies?
     res = Net::HTTP.get_response(URI.parse("http://#@addr:#@port/foo/xcookie"))
     assert_equal "200", res.code