about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-06-10 21:45:54 +0000
committerEric Wong <normalperson@yhbt.net>2010-06-10 22:08:00 +0000
commitee0088ea9906701f0c89e89ce78acd9d4820ee65 (patch)
tree979d21bfb1f5cb55561b4b57f49469ccbf3f5e86
parent5e8979ad38efdc4de3a69cc53aea33710d478406 (diff)
downloadunicorn-ee0088ea9906701f0c89e89ce78acd9d4820ee65.tar.gz
-rw-r--r--lib/unicorn/configurator.rb8
-rwxr-xr-xt/t0302-rails3-alt-working_directory.sh32
-rw-r--r--t/t0303-rails3-alt-working_directory_config.ru.sh48
3 files changed, 84 insertions, 4 deletions
diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb
index 0716e64..b1a317e 100644
--- a/lib/unicorn/configurator.rb
+++ b/lib/unicorn/configurator.rb
@@ -59,6 +59,9 @@ module Unicorn
 
       parse_rackup_file
 
+      # unicorn_rails creates dirs here after working_directory is bound
+      after_reload.call if after_reload
+
       # working_directory binds immediately (easier error checking that way),
       # now ensure any paths we changed are correctly set.
       [ :pid, :stderr_path, :stdout_path ].each do |var|
@@ -67,9 +70,6 @@ module Unicorn
         File.writable?(path) || File.writable?(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:
@@ -456,7 +456,7 @@ module Unicorn
 
       if daemonize
         # unicorn_rails wants a default pid path, (not plain 'unicorn')
-        if ru == :rails
+        if after_reload
           spid = set[:pid]
           pid('tmp/pids/unicorn.pid') if spid.nil? || spid == :unset
         end
diff --git a/t/t0302-rails3-alt-working_directory.sh b/t/t0302-rails3-alt-working_directory.sh
new file mode 100755
index 0000000..0a8894e
--- /dev/null
+++ b/t/t0302-rails3-alt-working_directory.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+. ./test-rails3.sh
+
+t_plan 3 "Rails 3 (beta) inside alt working_directory (no config.ru)"
+
+t_begin "setup and start" && {
+        unicorn_setup
+        rails3_app=$(cd rails3-app && pwd)
+        rm -rf $t_pfx.app
+        mkdir $t_pfx.app
+        cd $t_pfx.app
+        ( cd $rails3_app && tar cf - . ) | tar xf -
+        rm config.ru
+        $RAKE db:sessions:create
+        $RAKE db:migrate
+        unicorn_setup
+        rm $pid
+        echo "working_directory '$t_pfx.app'" >> $unicorn_config
+        cd /
+        unicorn_rails -D -c $unicorn_config
+        unicorn_wait_start
+}
+
+t_begin "static file serving works" && {
+        test x"$(curl -sSf http://$listen/x.txt)" = xHELLO
+}
+
+t_begin "killing succeeds" && {
+        kill $unicorn_pid
+}
+
+t_done
diff --git a/t/t0303-rails3-alt-working_directory_config.ru.sh b/t/t0303-rails3-alt-working_directory_config.ru.sh
new file mode 100644
index 0000000..b41215e
--- /dev/null
+++ b/t/t0303-rails3-alt-working_directory_config.ru.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+. ./test-rails3.sh
+
+t_plan 4 "Rails 3 (beta) inside alt working_directory (w/ config.ru)"
+
+t_begin "setup and start" && {
+        unicorn_setup
+        rtmpfiles unicorn_config_tmp
+        rails3_app=$(cd rails3-app && pwd)
+        rm -rf $t_pfx.app
+        mkdir $t_pfx.app
+        cd $t_pfx.app
+        ( cd $rails3_app && tar cf - . ) | tar xf -
+        $RAKE db:sessions:create
+        $RAKE db:migrate
+        unicorn_setup
+        rm $pid
+
+        echo "#\\--daemonize --host $host --port $port" \
+             >> $t_pfx.app/config.ru
+
+        # we have --host/--port in config.ru instead
+        grep -v ^listen $unicorn_config |
+          grep -v ^pid > $unicorn_config_tmp
+        echo "working_directory '$t_pfx.app'" >> $unicorn_config_tmp
+        cd /
+        unicorn_rails -c $unicorn_config_tmp
+}
+
+t_begin "pids in the right place" && {
+        if test -e $pid
+        then
+                die "pid=$pid not expected"
+        fi
+
+        unicorn_rails_pid="$t_pfx.app/tmp/pids/unicorn.pid"
+        unicorn_pid=$(cat $unicorn_rails_pid)
+}
+
+t_begin "static file serving works" && {
+        test x"$(curl -sSf http://$listen/x.txt)" = xHELLO
+}
+
+t_begin "killing succeeds" && {
+        kill $unicorn_pid
+}
+
+t_done