Forum: Ruby on Rails FCGI and the never ending saga of deploying on Dreamhost

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Richard L. (Guest)
on 2006-05-09 17:33
(Received via mailing list)
I'm trying to setup an app on Dreamhost and running into no end of
problems.

The app is running with edge rails and I'm currently getting the dreaded
'Rails application failed to start' white screen when trying to access
it.

I've gone through all the 'gotchas' and troubleshooting docs at
Dreamhost and the rails wiki to no avail.

Running script/console works fine.
Running script/server works fine (so I can access the site through port
3000)

Running dispatch.* from command line results in 500 error, which is what
is expected it it's working as far as I can tell.

No entries are made in the rails logs, but in the Apache error log I get
the following:

[Tue May  9 06:29:01 2006] [error] [client 194.80.32.10] FastCGI: comm
with (dynamic) server
"/home/rlivsey/thatsprogress.com/2006.05.02/public/dispatch.fcgi"
aborted: (first read) idle timeout (120 sec)
[Tue May  9 06:29:01 2006] [error] [client 194.80.32.10] FastCGI:
incomplete headers (0 bytes) received from server
"/home/rlivsey/thatsprogress.com/2006.05.02/public/dispatch.fcgi"

 From this the problem would appear to stem from fcgi, but I have no
idea what is wrong.

Any advice would be extremely welcome!

Thanks in advance.
Brian H. (Guest)
on 2006-05-09 22:02
(Received via mailing list)
Sure.
Modify your public/dispatch.fcgi to prevent Dreamhost from killing your
app.
The fix is really simple. Here's the complete file which should work
nicely.
Check the first line though to make sure that you retain the correct
shebang
(#!/usr/bin/ruby) line.

To improve performance, you should consider writing a cron task that
will
periodically request a page from your site.

do

crontab -e

add this line

0,5,10,15,20,25,30,35,40,45,50,55 * * * * curl -s
http://www.yourhost.com/your_non_cached_file/ > /dev/null

then save the file.   This should keep your site alive and healthy. It's
worked for me on Dreamhost for about 6 months now.


#!/usr/bin/ruby
#
# You may specify the path to the FastCGI crash log (a log of unhandled
# exceptions which forced the FastCGI instance to exit, great for
debugging)
# and the number of requests to process before running garbage
collection.
#
# By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log
# and the GC period is nil (turned off).  A reasonable number of
requests
# could range from 10-100 depending on the memory footprint of your app.
#
# Example:
#   # Default log path, normal GC behavior.
#   RailsFCGIHandler.process!
#
#   # Default log path, 50 requests between GC.
#   RailsFCGIHandler.process! nil, 50
#
#   # Custom log path, normal GC behavior.
#   RailsFCGIHandler.process! '/var/log/myapp_fcgi_crash.log'
#
require File.dirname(__FILE__) + "/../config/environment"
require 'fcgi_handler'

class RailsFCGIHandler
    SIGNALS = {
        'TERM' => :exit_now,
    }

    def exit_now_handler(signal)
        dispatcher_log :info, "ignoring request to terminate
immediately"
    end
end

RailsFCGIHandler.process!

# end of file
Al E. (Guest)
on 2006-05-10 16:06
Richard L. wrote:
> I'm trying to setup an app on Dreamhost and running into no end of
> problems.
>
> The app is running with edge rails and I'm currently getting the dreaded
> 'Rails application failed to start' white screen when trying to access
> it.
>
> I've gone through all the 'gotchas' and troubleshooting docs at
> Dreamhost and the rails wiki to no avail.
>
> Running script/console works fine.
> Running script/server works fine (so I can access the site through port
> 3000)
>
> Running dispatch.* from command line results in 500 error, which is what
> is expected it it's working as far as I can tell.
>
> No entries are made in the rails logs, but in the Apache error log I get
> the following:
>
> [Tue May  9 06:29:01 2006] [error] [client 194.80.32.10] FastCGI: comm
> with (dynamic) server
> "/home/rlivsey/thatsprogress.com/2006.05.02/public/dispatch.fcgi"
> aborted: (first read) idle timeout (120 sec)
> [Tue May  9 06:29:01 2006] [error] [client 194.80.32.10] FastCGI:
> incomplete headers (0 bytes) received from server
> "/home/rlivsey/thatsprogress.com/2006.05.02/public/dispatch.fcgi"
>
>  From this the problem would appear to stem from fcgi, but I have no
> idea what is wrong.
>
> Any advice would be extremely welcome!
>
> Thanks in advance.

I haven't really got much to add to what Brian H. said above. Are you
certain the "hashbang" line in your dispatch.fcgi script is pointing to
the right copy of Ruby?

Log in via ssh, try to get to your site, then type "ps aux | grep
dispatch" in the shell window. Does your dispatch process show up? If
not, it's somehow failing to start.

Like Brian, I've found it useful to ping my site periodically. I do it
with a script on my desktop box, instead of via a cron job. This way, I
know the frequency of errors, which seems to run about four a day. (User
voodoo ahead!) I think that what this accomplishes is to prevent my FCGI
process from getting swapped out. If it has to swap in to respond, it
times out, and the server starts another one, which can take 15-20
seconds.

Unlike Brian, I found that ignoring exit requests just led to a lot of
spare FCGI processes that I had to kill manually.

I think the performance of my site has improved since I set up an svn
repository on it, at which time it started being served by Apache 2.0
instead of 1.3.

I started using Dreamhost about the time they first tried to upgrade to
Rails 1.1. Having noted the stories of problems, and since I had plenty
of space, I built and installed my own copies of all the software I was
going to use. This may be overkill, but at least it doesn't change out
from under me!

It did take some hacking and close monitoring, but I seem to get
reasonably acceptable performance now (on http://openprofile.net ).

Hope this helps! The first thing to do is to determine whether the FCGI
process is getting started correctly!

--Al Evans
Brian H. (Guest)
on 2006-05-10 17:35
(Received via mailing list)
I forgot to mention..... start your app in production mode with
WEBrick....
that works there.

ruby script/server -e production


Then go to your site in a browser (be sure to use port 3000!) and see if
it
works there. At least then you know your site works on their servers and
it's not something silly like a database connection problem or a missing
Gem.
Erlend S. (Guest)
on 2006-05-10 17:45
(Received via mailing list)
One thing which has bitten me is that
#!/usr/bin/env ruby
works fine from every command originating from the console and via CGI,
but only
#!/usr/local/bin/ruby
works reliably under FastCGI.

-- Erlend
Jim Hughes (Guest)
on 2006-05-10 17:54
(Received via mailing list)
Are you using engines?  If so, DH's upgrade to 1.1.2 might've broken
your app.  You can fix it by commenting line 3 in engines.rb, which
says "require 'rails_version'".

Jim
LaMoukat (Guest)
on 2006-05-18 21:57
(Received via mailing list)
I have the same problem since a couple of weeks.
script/server works fine in production.
public/dispatch.cfgi run with my own build of ruby (500 internal error,
good html error page, no ruby errors or warnings).
This is not the problem of somr 500 error which comes once in a while
because of dreamhost fast-cgi garbadge collector : the app won't even
start.
John T. (Guest)
on 2007-01-17 20:01
Hi,
I'm running to the same problem trying to deploy Mephisto-0.7.3 with
edge rails on Dreamhost.

Running in development mode works no problem.
Running in production mode via webrick @ port 3000 works no problem.
But darned if I can't get it to run via fastcgi.

I've followed most of the guides out there, but to no avail.

I got a very basic rails app to run no problem via fastCGI as well, but
not the Mephisto blog. Yet if I use the same .htaccess configuration and
dispatch.fcgi, it won't work.

I wonder if it might be a memory-size issue? Is Mephisto a particularly
large rails app compared to others out there? It's much larger than my
own personal rails app.

Any further hints and help would be greatly appreciated...

John.

LaMoukat wrote:
> I have the same problem since a couple of weeks.
> script/server works fine in production.
> public/dispatch.cfgi run with my own build of ruby (500 internal error,
> good html error page, no ruby errors or warnings).
> This is not the problem of somr 500 error which comes once in a while
> because of dreamhost fast-cgi garbadge collector : the app won't even
> start.
This topic is locked and can not be replied to.