LiteSpeed Technologies
Download Download     Blog Blog     Wiki Wiki     Forum Forum     Store     Contact Contact    

Go Back   LiteSpeed Support Forums > External Applications > Ruby/Rails > my rails runner

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-03-2010, 04:26 AM
Grzegorz Derebecki Grzegorz Derebecki is offline
Senior Member
 
Join Date: Jun 2007
Posts: 92
Default my rails runner

I want share with you my modified RailsRunner it works only with rack rails 2.3 i had separate RailsRunner for older version to if somone want i can post it too

There is a few modifications:

1. Process name changed now we see what is process name
it looks like:

91436 ?? S 3:33.42 ruby: RAILS: fdb.pl (production) (ruby)
91437 ?? S 3:53.94 ruby: RAILS: fdb.pl (production) (ruby)
91438 ?? S 3:29.63 ruby: RAILS: fdb.pl (production) (ruby)
91439 ?? S 3:49.33 ruby: RAILS: fdb.pl (production) (ruby)

you must set APP_NAME varible in litespeed env or it will use directory where you app is placed.


2. second change is FIX problem with ENV varible
after call server = Rack::Handler::LSWS ENV varible disaperd i rewrite it again.

Code:
#!/opt/ruby/bin/ruby 
#
Dir.chdir(ENV['RAILS_ROOT'])

$0="RAILS: #{ENV['APP_NAME'] || ENV['RAILS_ROOT']} (#{ENV['RAILS_ENV']})"
if GC.respond_to?(:copy_on_write_friendly=)
   GC.copy_on_write_friendly = true
end


require 'config/boot'
require 'active_support'
require 'action_controller'
require 'fileutils'

options = {
  :environment => (ENV['RAILS_ENV'] || "development").dup,
  :config => RAILS_ROOT + "/config.ru",
  :detach => false,
  :debugger => false
}

# fix bug in lsapi (ENV var disapper)
env = ENV
server = Rack::Handler::LSWS
env.each { |k,v| ENV[k] ||= v }

if File.exist?(options[:config])
  config = options[:config]
  if config =~ /\.ru$/
    cfgfile = File.read(config)
    if cfgfile[/^#\\(.*)/]
      opts.parse!($1.split(/\s+/))
    end
    inner_app = eval("Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, config)
  else
    require config
    inner_app = Object.const_get(File.basename(config, '.rb').capitalize)
  end
else
  require 'config/environment'
  inner_app = ActionController::Dispatcher.new
end

app = Rack::Builder.new {
  use Rails::Rack::Static
  use Rails::Rack::Debugger if options[:debugger]
  run inner_app
}.to_app

ActiveRecord::Base.clear_all_connections! if defined?(ActiveRecord::Base)


begin
  server.run(app, options.merge(:AccessLog => []))
ensure
  puts 'Exiting'
end

hope that we be usefull for somone
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:33 AM.



- Archive - Top
© Copyright 2003-2011 LiteSpeed Technologies, Inc. All rights reserved. Privacy Policy.