The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Tip: TextDrive and Lighttpd

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jamis Buck

Posts: 184
Nickname: minam
Registered: Oct, 2004

Jamis Buck is a C/Java software developer for BYU, and hacks in Ruby for fun.
Tip: TextDrive and Lighttpd Posted: Feb 13, 2006 8:44 AM
Reply to this message Reply

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.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jamis Buck
Latest Posts From the buckblogs here

Advertisement

Here’s a tip if you’re running rails applications under lighttpd on TextDrive: don’t use static fcgi processes.

The static FCGI processes are the ones you get when you specify a bin-path in your configuration, a la:

  fastcgi.server = ( ".fcgi" =>
    ( "localhost" =>
        (
          "min-procs" => 1,
          "max-procs" => 1,
          "bin-path" => "public/dispatch.fcgi",
          "bin-environment" => ( "RAILS_ENV" => "production" )
        )
    )
  )

There are two problems with doing it this way:

  1. 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.
  2. 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:

  APP=yourapp
  ROOT=/home/you/path/to/$APP
  TMP=$ROOT/tmp
  ENV=production

  RAILS_ENV=$ENV spawn-fcgi -f $ROOT/public/dispatch.fcgi \
     -s $TMP/$APP-0.socket -P $TMP/$APP-0.pid
  RAILS_ENV=$ENV spawn-fcgi -f $ROOT/public/dispatch.fcgi \
     -s $TMP/$APP-1.socket -P $TMP/$APP-1.pid

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:

  fastcgi.server = ( ".fcgi" =>
     ( "localhost" =>
       ( "socket" => "/home/you/path/to/APP/tmp/APP-0.socket" ),
       ( "socket" => "/home/you/path/to/APP/tmp/APP-1.socket" )))

(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.)

Read: Tip: TextDrive and Lighttpd

Topic: MP4 to MP3 one liner Previous Topic   Next Topic Topic: Sigue la controversia de Java y el Decreto 3.390

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use