This post originated from an RSS feed registered with Ruby Buzz
by Jamis Buck.
Original Post: Tip: TextDrive and Lighttpd
Feed Title: the buckblogs here
Feed URL: http://weblog.jamisbuck.org/blog.cgi/programming/index.rss
Feed Description: Jamis Buck's corner of the blogging universe. Mostly about ruby, but includes ramblings on a variety of topics.
Lighttpd doesn’t always like the way the Rails’ reaper process plays with its processes, so you sometimes need to restart lighttpd when deploying a new version of your application.
Restarting lighttpd becomes extremely expensive, because all of the fastcgi processes get started up. With a single application that’s not a big deal, but if you start running more than one, you begin hating life when you have to restart lighttpd.
So, the solution?
First, create a tmp directory in your rails project.
Then, create a spawn script that looks something like this:
Go ahead and run this script. (What this does is spawn your fcgi processes externally. In this case, it spawns two processes, each listening on a different unix domain socket.)
Finally, tweak your lighttpd configuration so that it references the externally spawned fastcgi processes, instead of spawning directly:
(Be sure to replace the paths with the correct paths that were specified in the spawn script.) Then, restart lighttpd. Lighttpd will balance requests between the sockets you specify, so you can specify as few or as many as you need. (The fewer you use, the happier the TextDrive staff will be.)
Now, you can use the Rails reaper command with confidence to restart your application, and restarting lighttpd is a very light, very inexpensive affair because your fastcgi processes are managed independently. You can now tweak your lighttpd configuration without fear!
(Note, however, that a reboot of the machine hosting your account will require you to run the spawn scripts for your applications again… I’m sure there’s a handy solution for that floating around somewhere, but I don’t know it offhand.)