Ruby Setup - LSAPI

Discussion in 'Ruby/Rails' started by Xorlev, Apr 28, 2006.

  1. Xorlev

    Xorlev New Member

    Okay, so I'm setting up Ruby (not Ruby on Rails) to work with LSWS with the new LSAPI module, and I need a little help. I decided to use the dispatcher, so I created a LSAPI module with a url of a /tmp/lshttpd/ruby_ns.sock, and the command being the lsruby_runner.rb script. I added a Script Handler for .rb, and it's returning a 503...I know I'm doing something wrong, which is why I'm asking for a little help here. :)
  2. mistwang

    mistwang LiteSpeed Staff

    Have you built and installed the ruby extension? Is execution bit enabled for ruby_runner.rb?
    For trouble shooting, please check lsws/logs/error.log and stderr.log
  3. Xorlev

    Xorlev New Member

    Yes, I built and installed the Ruby extension, and it is chmodded to allow execution.

    Log:

    Code:
    2006-04-28 00:02:44.121 [DEBUG] [66.243.195.111:63346-0#Nanoshock] New request:
            Method=[GET], URI=[/ruby/testcgi.rb],
            QueryString=[]
            Content Length=0
    2006-04-28 00:02:44.121 [DEBUG] [66.243.195.111:63346-0#Nanoshock] Find context with URI: [/], location: [/home/nano/public_html/]
    2006-04-28 00:02:44.122 [DEBUG] [66.243.195.111:63346-0#Nanoshock] Find handler [RubyLSAPI] for [.rb]
    2006-04-28 00:02:44.122 [DEBUG] [66.243.195.111:63346-0#Nanoshock] processContextPath() return 0
    2006-04-28 00:02:44.122 [DEBUG] [66.243.195.111:63346-0#Nanoshock] run lsapi processor.
    2006-04-28 00:02:44.122 [DEBUG] [uds://tmp/lshttpd/ruby_ns.sock] request [66.243.195.111:63346-0#Nanoshock:lsapi] is assigned with connection!
    2006-04-28 00:02:44.122 [DEBUG] [66.243.195.111:63346-0#Nanoshock:lsapi] [ExtConn] reconnect()
    2006-04-28 00:02:44.122 [DEBUG] [66.243.195.111:63346-0#Nanoshock:lsapi] connection to [uds://tmp/lshttpd/ruby_ns.sock] on request 0, error: No such file or directory!
    2006-04-28 00:02:44.122 [DEBUG] [66.243.195.111:63346-0#Nanoshock:lsapi] [ExtConn] close()
    2006-04-28 00:02:44.122 [DEBUG] [uds://tmp/lshttpd/ruby_ns.sock] No Request has been processed successfully through this connection, the maximum connections allowed will be reduced!
    2006-04-28 00:02:44.122 [INFO] [uds://tmp/lshttpd/ruby_ns.sock] Connection refused, restart!
    etc. until it gives up and sends the error.
  4. mistwang

    mistwang LiteSpeed Staff

    Don't know what exactly is the problem, below is our RubyRunner configuration, you can give it a try.


    Code:
    Name RubyRunner 
    Address uds://tmp/lshttpd/rubyrunner.sock 
    Max Connections 10 
    Environment N/A 
    Initial Request Timeout (secs) 60 
    Retry Timeout (secs) 0 
    Persistent Connection Yes 
    Connection Keepalive Timeout N/A 
    Response Bufferring No 
    Auto Start Yes 
    Command $SERVER_ROOT/fcgi-bin/lsruby_runner.rb 
    Back Log 10 
    Instances 10 
    
  5. Xorlev

    Xorlev New Member

    Okay, it's halfway working now (no more errors in log), but now it returns a 500 error.

    Settings:

    Code:
    Name	RubyRunner
    Address	uds://tmp/lshttpd/rubyrunner.sock
    Max Connections	10
    Environment	N/A
    Initial Request Timeout (secs)	60
    Retry Timeout (secs)	0
    Persistent Connection	Yes
    Connection Keepalive Timeout	N/A
    Response Bufferring	No
    Auto Start	Yes
    Command	$SERVER_ROOT/fcgi-bin/lsruby_runner.rb
    Back Log	10
    Instances	10
    Log:

    Code:
    2006-05-02 20:40:05.480	DEBUG	[64.191.7.230:80] New connection from 64.191.7.230:37065.
    2006-05-02 20:40:05.480	DEBUG	[64.191.7.230:80] 1 connections accepted!
    2006-05-02 20:40:05.481	DEBUG	[64.191.7.230:37065-0] HttpIOLink::handleEvents() events=1!
    2006-05-02 20:40:05.481	DEBUG	[64.191.7.230:37065-0] HttpConnection::onReadEx(), state: 0!
    2006-05-02 20:40:05.482	DEBUG	[64.191.7.230:37065-0] readToHeaderBuf().
    2006-05-02 20:40:05.482	DEBUG	[64.191.7.230:37065-0] Read from client: 313
    2006-05-02 20:40:05.482	DEBUG	[64.191.7.230:37065-0] read 313 bytes to header buffer
    2006-05-02 20:40:05.482	DEBUG	[64.191.7.230:37065-0] processHeader() return 0, header state: 3.
    2006-05-02 20:40:05.482	DEBUG	[64.191.7.230:37065-0] readToHeaderBuf() return 0.
    2006-05-02 20:40:05.482	DEBUG	[64.191.7.230:37065-0#RubyNanoshock] New request:
    Method=[GET], URI=[/testcgi.rb],
    QueryString=[]
    Content Length=0
    2006-05-02 20:40:05.482	DEBUG	[64.191.7.230:37065-0#RubyNanoshock] Find context with URI: [/], location: [/home/nano/public_html/ruby/]
    2006-05-02 20:40:05.482	DEBUG	[64.191.7.230:37065-0#RubyNanoshock] Find handler [RubyRunner] for [.rb]
    2006-05-02 20:40:05.482	DEBUG	[64.191.7.230:37065-0#RubyNanoshock] processContextPath() return 0
    2006-05-02 20:40:05.482	DEBUG	[64.191.7.230:37065-0#RubyNanoshock] run lsapi processor.
    2006-05-02 20:40:05.482	DEBUG	[uds://tmp/lshttpd/rubyrunner.sock] create new connection succeed!
    2006-05-02 20:40:05.482	DEBUG	[uds://tmp/lshttpd/rubyrunner.sock] request [64.191.7.230:37065-0#RubyNanoshock:lsapi] is assigned with connection!
    2006-05-02 20:40:05.482	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] [ExtConn] reconnect()
    2006-05-02 20:40:05.483	DEBUG	[RubyRunner] add child process pid: 404
    2006-05-02 20:40:05.484	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] ExtConn::onWrite()
    2006-05-02 20:40:05.484	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] request header is done
    2006-05-02 20:40:05.484	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] ExtConn::continueRead()
    2006-05-02 20:40:05.484	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] Request body done!
    2006-05-02 20:40:05.484	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] ExtConn::suspendWrite()
    2006-05-02 20:40:05.484	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] processNewReq() return 0.
    2006-05-02 20:40:05.498	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] ExtConn::onRead()
    2006-05-02 20:40:05.498	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] LsapiConn::doRead()
    2006-05-02 20:40:05.498	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] process packet header 8 bytes
    2006-05-02 20:40:05.498	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] process packet header 0 bytes
    2006-05-02 20:40:05.538	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] ExtConn::onRead()
    2006-05-02 20:40:05.539	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] LsapiConn::doRead()
    2006-05-02 20:40:05.539	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] process packet header 8 bytes
    2006-05-02 20:40:05.539	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] process response header 8 bytes
    2006-05-02 20:40:05.539	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] process packet header 8 bytes
    2006-05-02 20:40:05.539	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] [EXT] EndResponse( endCode=0, protocolStatus=0 )
    2006-05-02 20:40:05.539	NOTICE	[64.191.7.230:37065-0#RubyNanoshock:lsapi] Premature end of response header.
    2006-05-02 20:40:05.539	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] HttpIOLink::continueWrite()...
    2006-05-02 20:40:05.539	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] write resumed!
    2006-05-02 20:40:05.539	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] HttpIOLink::handleEvents() events=4!
    2006-05-02 20:40:05.539	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] HttpIOLink::suspendWrite()...
    2006-05-02 20:40:05.539	DEBUG	[64.191.7.230:37065-0#RubyNanoshock:lsapi] HttpConnection::sendHttpError(),code=500 Internal Server Error
  6. mistwang

    mistwang LiteSpeed Staff

    I am not exactly sure what is the problem, maybe support for your ruby script is poor. You can try the following hello.rb, if it works, please send us your testing script, we will figure out the problem.

    Code:
    #!/usr/local/bin/ruby
    
    print "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\nHello World!\r\n"
    ENV.each_pair {|key, value| print "#{key} is #{value}
    \r\n" }
    
  7. Xorlev

    Xorlev New Member

    Aha it works now with the script you gave me, however it appears your testcgi.rb script is malfunctioning on my setup, which was what "test.rb" was.
  8. mistwang

    mistwang LiteSpeed Staff

    testcgi.rb itself is using LSAPI interface, it is for testing the ruby "cgi" extension under LSAPI. Itself is a LSAPI application, It will not work under the lsruby_runner.
  9. Xorlev

    Xorlev New Member

    Aha, I should have thought of that. :oops:

    Thank you for your help, and out of curiousity how would I make LSAPI work directly from the script (ie, requiring it in then using the blocks given)? A context?
  10. mistwang

    mistwang LiteSpeed Staff

    Yes, the extra code for LSAPI is pretty simple.
    You need to define a LSAPI application for each LSAPI ruby script, then mount the application via a context or script handler.
  11. Xorlev

    Xorlev New Member

    Thank you for you help. Ruby is now chugging along happily :)

Share This Page