From: Eric Wong <normalperson@yhbt.net>
To: mongrel-unicorn@rubyforge.org
Subject: unicorn_rails cleanup (possible fix for Rails3) pushed
Date: Fri, 4 Jun 2010 01:58:38 +0000 [thread overview]
Message-ID: <20100604015838.GA21464@dcvr.yhbt.net> (raw)
Hi all,
I've pushed the following patch out go git://git.bogomips.org/unicorn
along with a few other Rails-related test updates. This is more of a
shotgun fix (but less code is better :) since I haven't been able to
reproduce the brokeness people have been seeing with "unicorn_rails"
and Rails 3 betas.
Even though "unicorn" works perfectly well for Rails3, some folks will
inevitably run "unicorn_rails" because of the "rails" in its name.
If I were to do it all over again, I would've just made everybody write
config.ru files for Rails. But yes, programming is like sex, make one
mistake and support it for life :)
You can grab a git gem here, too:
http://unicorn.bogomips.org/files/unicorn-0.99.0.16.g59a625.gem
>From 4b44e21957e4cb8ec6ace5604fbe096dfd8959d2 Mon Sep 17 00:00:00 2001
From: Eric Wong <normalperson@yhbt.net>
Date: Thu, 3 Jun 2010 22:52:11 +0000
Subject: [PATCH] unicorn_rails: avoid duplicating config.ru logic
This should allow "unicorn_rails" to be used seamlessly
with Rails 3 projects which package config.ru for you.
---
bin/unicorn_rails | 50 ++++++++++++++------------------------------------
1 files changed, 14 insertions(+), 36 deletions(-)
diff --git a/bin/unicorn_rails b/bin/unicorn_rails
index 72ab288..45a9b11 100755
--- a/bin/unicorn_rails
+++ b/bin/unicorn_rails
@@ -109,53 +109,30 @@ end
ru = ARGV[0] || (File.exist?('config.ru') ? 'config.ru' : nil)
-if ru && ru =~ /\.ru\z/
- # parse embedded command-line options in config.ru comments
- /^#\\(.*)/ =~ File.read(ru) and opts.parse!($1.split(/\s+/))
-end
-
-def rails_builder(ru, daemonize)
+def rails_builder(daemonize)
# this lambda won't run until after forking if preload_app is false
lambda do ||
# Load Rails and (possibly) the private version of Rack it bundles.
begin
require 'config/boot'
+ require 'config/environment'
rescue LoadError => err
abort "#$0 must be run inside RAILS_ROOT: #{err.inspect}"
end
- inner_app = case ru
- when nil
- require 'config/environment'
-
- defined?(::Rails::VERSION::STRING) or
- abort "Rails::VERSION::STRING not defined by config/{boot,environment}"
- # it seems Rails >=2.2 support Rack, but only >=2.3 requires it
- old_rails = case ::Rails::VERSION::MAJOR
- when 0, 1 then true
- when 2 then Rails::VERSION::MINOR < 3 ? true : false
- else
- false
- end
-
- if old_rails
- require 'unicorn/app/old_rails'
- Unicorn::App::OldRails.new
- else
- ActionController::Dispatcher.new
- end
- when /\.ru$/
- raw = File.read(ru)
- raw.sub!(/^__END__\n.*/, '')
- eval("Rack::Builder.new {(#{raw}\n)}.to_app", TOPLEVEL_BINDING, ru)
+ defined?(::Rails::VERSION::STRING) or
+ abort "Rails::VERSION::STRING not defined by config/{boot,environment}"
+ # it seems Rails >=2.2 support Rack, but only >=2.3 requires it
+ old_rails = case ::Rails::VERSION::MAJOR
+ when 0, 1 then true
+ when 2 then Rails::VERSION::MINOR < 3 ? true : false
else
- require ru
- Object.const_get(File.basename(ru, '.rb').capitalize)
+ false
end
Rack::Builder.new do
map_path = ENV['RAILS_RELATIVE_URL_ROOT'] || '/'
- if inner_app.class.to_s == "Unicorn::App::OldRails"
+ if old_rails
if map_path != '/'
# patches + tests welcome, but I really cbf to deal with this
# since all apps I've ever dealt with just use "/" ...
@@ -163,23 +140,24 @@ def rails_builder(ru, daemonize)
end
$stderr.puts "LogTailer not available for Rails < 2.3" unless daemonize
$stderr.puts "Debugger not available" if $DEBUG
+ require 'unicorn/app/old_rails'
map(map_path) do
use Unicorn::App::OldRails::Static
- run inner_app
+ run Unicorn::App::OldRails.new
end
else
use Rails::Rack::LogTailer unless daemonize
use Rails::Rack::Debugger if $DEBUG
map(map_path) do
use Rails::Rack::Static
- run inner_app
+ run ActionController::Dispatcher.new
end
end
end.to_app
end
end
-app = rails_builder(ru, daemonize)
+app = ru ? Unicorn.builder(ru, opts) : rails_builder(daemonize)
options[:listeners] << "#{host}:#{port}" if set_listener
if $DEBUG
--
Eric Wong
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying
next reply other threads:[~2010-06-04 1:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-04 1:58 Eric Wong [this message]
2010-06-04 2:13 ` unicorn_rails cleanup (possible fix for Rails3) pushed Michael Guterl
2010-06-04 2:48 ` Eric Wong
2010-06-08 2:49 ` Eric Wong
-- strict thread matches above, loose matches on Subject: below --
2010-06-08 12:24 Hongli Lai
2010-06-08 19:20 ` Eric Wong
2010-06-08 19:25 ` Hongli Lai
2010-06-08 20:55 ` Eric Wong
2010-06-11 20:32 ` Eric Wong
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=20100604015838.GA21464@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).