Will there be official support for Rails >= 2.3

#1
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.
 
#3
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:
Code:
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:
Code:
Dir.chdir(File.join(File.dirname(__FILE__), '..'))

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

require 'config/environment'

Rack::Handler::LSWS.run(ActionController::Dispatcher.new)
When I request a page from the app I get the following error:
Code:
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:
Code:
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.
 
#5
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

LiteSpeed Staff
#6
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.
 
#7
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:
Code:
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.
 
#8
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.
 

Attachments

mistwang

LiteSpeed Staff
#9
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

LiteSpeed Staff
#10
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.
 

mistwang

LiteSpeed Staff
#12
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

LiteSpeed Staff
#13
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

LiteSpeed Staff
#14
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?
 
#15
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

LiteSpeed Staff
#16
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 .
 
#18
actually, config/boot.rb does exactly what I want. just need to duplicate that code. :)
Based on running in the rails root:
Code:
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:
Code:
File.read("#{RAILS_ROOT}/config/environment.rb")
and it'll pull in the full file path too.

Ta
Luke
 

mistwang

LiteSpeed Staff
#19
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?
 
Top