unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: unicorn list <mongrel-unicorn@rubyforge.org>
Subject: Re: unicorn, rails, and symlinked deployment
Date: Wed, 18 Nov 2009 17:51:26 -0800	[thread overview]
Message-ID: <20091119015126.GB1935@dcvr.yhbt.net> (raw)
In-Reply-To: <20091118172118.GA17288@dcvr.yhbt.net>

Eric Wong <normalperson@yhbt.net> wrote:
> Michael Guterl <mguterl@gmail.com> wrote:
> > cd ~/public_html/rm/current
> > unicorn_rails -D -E production -c config/unicorn.rb
> > 
> > I determined the -c config/unicorn.rb was the problem.  If I change it to:
> > 
> > unicorn_rails -D -E production -c ~/public_html/rm/current/config/unicorn.rb
> > 
> > everything works fine.
> 
> Hmm, maybe the config file path shouldn't be expanded then.  Especially
> since it's only specified in the command-line.  /me ponders a bit...

Hi Michael,

Just pushed this out, too.  This should work better for you with:

  unicorn_rails -D -E production -c config/unicorn.rb

Oddly, this has been a problem since the beginning of time and probably
confused a good amount of people.

Thanks Michael for finally bringing it to my attention.  Most folks I
know favor absolute ones (including myself), and don't hit this
problem...  Of course let me know if I broke something for anyone,
I hope not...

>From 15217fe1162a400fa1cd2216e395d9f17be8083e Mon Sep 17 00:00:00 2001
From: Eric Wong <normalperson@yhbt.net>
Date: Wed, 18 Nov 2009 17:28:12 -0800
Subject: [PATCH] Do not expand paths given on the shell

Shells already expand '~' before the executables see it, and
relative paths inside symlinks can get set incorrectly to the
actual directory name, and not the (usually desired) symlink
name for things like Capistrano.

Since our paths are now unexpanded, we must now check the
"working_directory" directive and raise an error if the user
specifies the config file in a way that makes the config file
unreloadable.
---
 bin/unicorn                 |    4 +-
 bin/unicorn_rails           |    2 +-
 lib/unicorn/configurator.rb |    7 ++++++
 test/exec/test_exec.rb      |   51 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/bin/unicorn b/bin/unicorn
index 225e819..325afb3 100755
--- a/bin/unicorn
+++ b/bin/unicorn
@@ -68,7 +68,7 @@ opts = OptionParser.new("", 24, '  ') do |opts|
   opts.on("-P", "--pid FILE", "DEPRECATED") do |f|
     warn %q{Use of --pid/-P is strongly discouraged}
     warn %q{Use the 'pid' directive in the Unicorn config file instead}
-    options[:pid] = File.expand_path(f)
+    options[:pid] = f
   end
 
   opts.on("-s", "--server SERVER",
@@ -85,7 +85,7 @@ opts = OptionParser.new("", 24, '  ') do |opts|
   end
 
   opts.on("-c", "--config-file FILE", "Unicorn-specific config file") do |f|
-    options[:config_file] = File.expand_path(f)
+    options[:config_file] = f
   end
 
   # I'm avoiding Unicorn-specific config options on the command-line.
diff --git a/bin/unicorn_rails b/bin/unicorn_rails
index 36ed660..e46de70 100755
--- a/bin/unicorn_rails
+++ b/bin/unicorn_rails
@@ -75,7 +75,7 @@ opts = OptionParser.new("", 24, '  ') do |opts|
   end
 
   opts.on("-c", "--config-file FILE", "Unicorn-specific config file") do |f|
-    options[:config_file] = File.expand_path(f)
+    options[:config_file] = f
   end
 
   opts.on("-P PATH", "DEPRECATED") do |v|
diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb
index 2d92aa3..e809b22 100644
--- a/lib/unicorn/configurator.rb
+++ b/lib/unicorn/configurator.rb
@@ -372,6 +372,13 @@ module Unicorn
     def working_directory(path)
       # just let chdir raise errors
       path = File.expand_path(path)
+      if config_file &&
+         config_file[0] != ?/ &&
+         ! test(?r, "#{path}/#{config_file}")
+        raise ArgumentError,
+              "config_file=#{config_file} would not be accessible in" \
+              " working_directory=#{path}"
+      end
       Dir.chdir(path)
       HttpServer::START_CTX[:cwd] = ENV["PWD"] = path
     end
diff --git a/test/exec/test_exec.rb b/test/exec/test_exec.rb
index f6dfd6a..49762c0 100644

<snip ridiculously verbose test case>
-- 
Eric Wong

  parent reply	other threads:[~2009-11-19  2:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-17 17:50 unicorn, rails, and symlinked deployment Michael Guterl
2009-11-17 22:08 ` Michael Guterl
2009-11-17 22:20 ` Eric Wong
2009-11-18 15:34   ` Michael Guterl
2009-11-18 17:21     ` Eric Wong
2009-11-18 19:47       ` Michael Guterl
2009-11-19  1:05         ` Eric Wong
2009-11-19  1:46           ` Eric Wong
2009-11-19  2:36             ` Michael Guterl
2009-11-19  1:51       ` Eric Wong [this message]
2009-11-19  2:45         ` Michael Guterl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/unicorn/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091119015126.GB1935@dcvr.yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=mongrel-unicorn@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).