# FCGI and the never ending saga of deploying on Dreamhost

**URL:** <https://www.ruby-forum.com/t/fcgi-and-the-never-ending-saga-of-deploying-on-dreamhost/60022>\
**Category:** Rails\
**Created:** [May 9, 2006, 3:33pm UTC](https://www.ruby-forum.com/t/fcgi-and-the-never-ending-saga-of-deploying-on-dreamhost/60022 "2006-05-09T15:33:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rjlyders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rjlyders](https://www.ruby-forum.com/u/rjlyders)\
**Post date:** [May 9, 2006, 3:33pm UTC](https://www.ruby-forum.com/t/fcgi-and-the-never-ending-saga-of-deploying-on-dreamhost/60022/1 "2006-05-09T15:33:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rjlyders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rjlyders](https://www.ruby-forum.com/u/rjlyders)\
**Post date:** [May 9, 2006, 8:02pm UTC](https://www.ruby-forum.com/t/fcgi-and-the-never-ending-saga-of-deploying-on-dreamhost/60022/2 "2006-05-09T20:02:14Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![rjlyders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rjlyders](https://www.ruby-forum.com/u/rjlyders)\
**Post date:** [May 10, 2006, 2:06pm UTC](https://www.ruby-forum.com/t/fcgi-and-the-never-ending-saga-of-deploying-on-dreamhost/60022/3 "2006-05-10T14:06:52Z")

</div>

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](http://openprofile.net) ).

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

–Al Evans

---

<div class="post-metadata">

**Author:** ![rjlyders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rjlyders](https://www.ruby-forum.com/u/rjlyders)\
**Post date:** [May 10, 2006, 3:35pm UTC](https://www.ruby-forum.com/t/fcgi-and-the-never-ending-saga-of-deploying-on-dreamhost/60022/4 "2006-05-10T15:35:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rjlyders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rjlyders](https://www.ruby-forum.com/u/rjlyders)\
**Post date:** [May 10, 2006, 3:54pm UTC](https://www.ruby-forum.com/t/fcgi-and-the-never-ending-saga-of-deploying-on-dreamhost/60022/5 "2006-05-10T15:54:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rjlyders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rjlyders](https://www.ruby-forum.com/u/rjlyders)\
**Post date:** [May 10, 2006, 3:45pm UTC](https://www.ruby-forum.com/t/fcgi-and-the-never-ending-saga-of-deploying-on-dreamhost/60022/6 "2006-05-10T15:45:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rjlyders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rjlyders](https://www.ruby-forum.com/u/rjlyders)\
**Post date:** [May 18, 2006, 7:57pm UTC](https://www.ruby-forum.com/t/fcgi-and-the-never-ending-saga-of-deploying-on-dreamhost/60022/7 "2006-05-18T19:57:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rjlyders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rjlyders](https://www.ruby-forum.com/u/rjlyders)\
**Post date:** [January 17, 2007, 7:01pm UTC](https://www.ruby-forum.com/t/fcgi-and-the-never-ending-saga-of-deploying-on-dreamhost/60022/8 "2007-01-17T19:01:15Z")

</div>

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.
