PDA

View Full Version : Will there be official support for Rails >= 2.3


tdinkins
01-26-2009, 09:08 AM
My company is developing some new Rails (2.3) applications and deploying on litespeed.

I know there are currently incompatibilities, but was wondering if the new Rails versions will get the same kind of support that the old versions do.

Being able to configure a rails app in just a few steps is a lot nicer than trying to work out how to get Rack and Litespeed to play nice.

mistwang
01-26-2009, 08:55 PM
add to our to-do list.

russ816
01-26-2009, 09:06 PM
I work with Tim and these are some of the errors that I've been running into.

This is the config for the external app for the vhost that the context is hooked to:

Name rails
Address uds://tmp/lshttpd/lsruby.sock
Command /opt/local/bin/ruby /opt/lsws/vhosts/rails/script/lsws.rb


This is the the contents of that file:

Dir.chdir(File.join(File.dirname(__FILE__), '..'))

require 'rubygems'
require 'lsapi'
require 'rack'

require 'config/environment'

Rack::Handler::LSWS.run(ActionController::Dispatch er.new)


When I request a page from the app I get the following error:

no such file to load -- /opt/local/lib/ruby/gems/1.8/gems/rack-0.9.1/lib/rack/handler/lsws.rb (MissingSourceFile)


Also, I'm not sure if this is related but I get an error when trying to load up the lsapi gem in irb:

irb(main):006:0> require 'lsapi'
LS=> true
LSD/opt/local/lib/ruby/1.8/irb/input-method.rb:97:in `readline'LS
: LS1wrong argument type LSAPI (expected File)LS
(LSTypeErrorLS
)
LSG from /opt/local/lib/ruby/1.8/irb/input-method.rb:97:in `gets'
LSA from /opt/local/lib/ruby/1.8/irb.rb:132:in `eval_input'
LSD from /opt/local/lib/ruby/1.8/irb.rb:263:in `signal_status'
LSA from /opt/local/lib/ruby/1.8/irb.rb:131:in `eval_input'
LSD from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:189:in `call'
LSI from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:189:in `buf_input'
LSD from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:104:in `getc'
LSD from /opt/local/lib/ruby/1.8/irb/slex.rb:206:in `match_io'
LS@ from /opt/local/lib/ruby/1.8/irb/slex.rb:76:in `match'
LSE from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:287:in `token'
LSC from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:263:in `lex'
LSX from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:234:in `each_top_level_statement'
LSD from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:230:in `loop'
LSX from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:230:in `each_top_level_statement'
LSE from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:229:in `catch'
LSX from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:229:in `each_top_level_statement'
LSA from /opt/local/lib/ruby/1.8/irb.rb:146:in `eval_input'
LS; from /opt/local/lib/ruby/1.8/irb.rb:70:in `start'
LS; from /opt/local/lib/ruby/1.8/irb.rb:69:in `catch'
LS; from /opt/local/lib/ruby/1.8/irb.rb:69:in `start'
LS$ from /opt/local/bin/irb:13


I've tried getting Rails 2.3 running with Rack on 3 different machine (CentOS, ArchLinux and Mac OSX), all with the same results.

russ816
01-26-2009, 09:08 PM
add to our to-do list.

Sorry, I was writing my post as you posted yours.
Thanks for the info.

sniperd
02-27-2009, 09:16 AM
Hi Mistwang,

Any update on getting lsws rails 2.3 complaint? I have a bunch of licenses purchased through you guys and plan on maybe even getting more with a large deployment of a new rails app, but if theirs no support on this we cannot use your product.....

mistwang
02-27-2009, 08:42 PM
Have taken some time to investigate it tonight, I think a piece of code similar to

rails-2.3.0/lib/commands/server.rb

should work, the main change is to use our Rack handler instead of Mongrel or WEBrick for the server object

server = Rack::Handler::LSWS

Might need some tweaks like our RailsRunner.rb

Due our tight schedule and Ruby programming skills, if any experienced Ruby/Rails developer would to take this project, please contact us. we will pay your time.

russ816
03-01-2009, 06:22 PM
I'm willing to give it a shot, but I'm running into strange errors when trying to include the Rack:LSWS handler.

When trying to include it from IRB I get:
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'rack'
=> true
irb(main):003:0> require 'rack/handler/lsws'
LS=> true
LSD/opt/local/lib/ruby/1.8/irb/input-method.rb:97:in `readline'LS
: LS1wrong argument type LSAPI (expected File)LS
(LSTypeErrorLS
)
LSG from /opt/local/lib/ruby/1.8/irb/input-method.rb:97:in `gets'
LSA from /opt/local/lib/ruby/1.8/irb.rb:132:in `eval_input'
LSD from /opt/local/lib/ruby/1.8/irb.rb:263:in `signal_status'
LSA from /opt/local/lib/ruby/1.8/irb.rb:131:in `eval_input'
LSD from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:189:in `call'
LSI from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:189:in `buf_input'
LSD from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:104:in `getc'
LSD from /opt/local/lib/ruby/1.8/irb/slex.rb:206:in `match_io'
LS@ from /opt/local/lib/ruby/1.8/irb/slex.rb:76:in `match'
LSE from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:287:in `token'
LSC from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:263:in `lex'
LSX from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:234:in `each_top_level_statement'
LSD from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:230:in `loop'
LSX from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:230:in `each_top_level_statement'
LSE from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:229:in `catch'
LSX from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:229:in `each_top_level_statement'
LSA from /opt/local/lib/ruby/1.8/irb.rb:146:in `eval_input'
LS; from /opt/local/lib/ruby/1.8/irb.rb:70:in `start'
LS; from /opt/local/lib/ruby/1.8/irb.rb:69:in `catch'
LS; from /opt/local/lib/ruby/1.8/irb.rb:69:in `start'
LS$ from /opt/local/bin/irb:13

I just don't understand the error messages it's giving.

russ816
03-01-2009, 08:26 PM
I think I got it. Just took some time to find the right combination of settings. I've attached the file that needs to be run. It uses the same setup you would use as a normal rack app with lsws. I'll post full details on the setup tomorrow.

mistwang
03-03-2009, 07:35 AM
Maybe it need updates on the LSAPI object definition. Make it derive from "File" object could make irb happy.
It is in ruby-lsapi/ext/lsapi/lsruby.c inside Init_lsapi() function.

mistwang
03-03-2009, 08:23 AM
I think I got it. Just took some time to find the right combination of settings. I've attached the file that needs to be run. It uses the same setup you would use as a normal rack app with lsws. I'll post full details on the setup tomorrow.
Thanks! It is very close what I thought.
Some code are not necessary, could clear it up a little bit.
Only one concern, our RailsRunner.rb takes care of the DB connection problem caused by fork(), so it close DB connection then reopen it after fork().

The default Rack::Handler::LSWS does not have this logic, so it may not work properly.

I am thinking about a dedicate Rack handler for Rails, maybe call it Rack::Handler::LSRAILS, it should be similar to Rack::Handler::LSWS, just add logic like the what we have in RailsRunner.rb . All the code could be in one file.

russ816
03-03-2009, 09:04 AM
I got around to cleaning it up a bit. I'm sure there are other issues, so I just put it up on github for fixes.

http://github.com/russ/litespeed-rails-runner/tree/master

mistwang
03-05-2009, 10:43 AM
That's good.

I think we still need to support older release of Rails and only use that for 2.3 and above.

In the code
ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord::Base)

may not work well unless the function has been added back in, seems it is missing in latest rails 2.2 release.
That's why we need to update RailsRunner.rb to discount and reconnect the connection manually in the latest version.

mistwang
03-10-2009, 11:50 AM
Looks like

ActiveRecord::Base.clear_active_connections!

is coming back into ActiveRecord::Base in rails 2.3, so it should be fine.
I have to make the RailsRunner.rb compatible with Rails 1.x 2.2 and 2.3 by combining the current RailsRunner.rb and the one you put up on github.

Is there any easy way to detect the Rails version being used at the beginning?

mistwang
03-16-2009, 10:26 AM
I am thinking adding ruby code to extract the version number from file "RAILS_ROOT/config/environment.rb, at the beginning of the file,
"RAILS_GEM_VERSION" is set to the version of Rails should be used.

Can anyone help with the ruby code?

kule
03-18-2009, 03:40 AM
I am thinking adding ruby code to extract the version number from file "RAILS_ROOT/config/environment.rb, at the beginning of the file,
"RAILS_GEM_VERSION" is set to the version of Rails should be used.

Can anyone help with the ruby code?

If I can help I will - what exactly are you after? Some additions to the github code above? e.g. do you just want to do something like

if RAILS_GEM_VERSION >= 2.3.2
# use rack
else
# use old system
end

or did you want to get the RAILS_GEM_VERSION number out to litespeed?

mistwang
03-18-2009, 06:15 AM
I am not sure we can do "require config/environment" at the beginning of the file or not. The code for 2.3 does not have that.
I am thinking about some ruby code to open config/environment.rb and search for RAILS_GEM_VERSION .

mistwang
03-18-2009, 06:22 AM
actually, config/boot.rb does exactly what I want. just need to duplicate that code. :)

kule
03-18-2009, 06:45 AM
actually, config/boot.rb does exactly what I want. just need to duplicate that code. :)

Based on running in the rails root:

environmentrb = File.read('config/environment.rb')
puts $1 if environmentrb =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/


If you have loaded rails then you can use:

File.read("#{RAILS_ROOT}/config/environment.rb")

and it'll pull in the full file path too.

Ta
Luke

mistwang
03-18-2009, 07:18 AM
I want to save the result in variable "raisl_ver"

environmentrb = File.read('config/environment.rb')
rails_ver = $1 if environmentrb =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/

Is above code correct?

kule
03-18-2009, 07:21 AM
I want to save the result in variable "raisl_ver"
Is above code correct?

Yep looks good to me.

kule
03-18-2009, 07:23 AM
Oh just to add - remember that we're using a regular expression to find the version. If it can't find the constant we're after rails_ver will end up being nil (similar to null in most other languages).

So you may want to check before using it:


if rails_ver.nil?
# assume old way or throw exception
else
# whatever you wish to do
end

mistwang
03-18-2009, 07:55 AM
Thanks!
Now, the RailsRunner.rb in the latest 4.0 release package should be compatible with all Rails release now.

pguy
03-25-2009, 11:07 PM
Is there any documentation on getting Rails 2.3 to work with LS 4.0?

mistwang
03-26-2009, 03:32 PM
Just replace the RailsRunner.rb with the one from LS 4.0. it should work with 3.3.24 release as well.