|
![]() |
Getting Started With SCGIThis is just a quick HOWTO document showing you how to get your Ruby On Rails application running under the SCGI Rails Runner server. I’ve heard of a few people who are testing this out for production deployment, so feel free to try it out and give me feedback. Some people have had problems with Typo in the past, but I test with Typo and it works for me. What Is SCGISCGI is an alternative protocol for a web server to run an application under the CGI system, but without starting the application over and over again. It’s like FastCGI but is much simpler to implement and simple is always a good thing. Running your Ruby On Rails application under the SCGI Rails Runner (SRR) will make it easy for you to run your application independent of the fronting web server, and should give you great performance without a lot of the management headaches associated with FastCGI and Rails. InstallThere are two requirements before you start:
You can install both via RubyGems, but the latest gems for SRR should include them as dependencies. After that, installation couldn’t be easier. You can either install via the RubyGem I provide or install directly from the source. To install SRR the easy way simply download the gem and install it directly:
Where If you’re allergic to RubyGems or have the need to install directly, then you can do the following:
If you don’t know what any of those commands do then just install the gem or learn to use Unix. Win32 NotesSee Win32 specific page for more information. The main things to know when running this all under Win32 are:
Setup SCGI in RailsOnce you’ve installed it you should get three commands:
The first thing you need to do is configure your processor using
This will configure your first processor for the default options. Check the file NOTE: Did you give a good password? You'll need to remember this for later. The password prevents people from accessing the SCGI processor's control protocol without your permission. Without it anyone who can connect to port 8999 (by default) could mess with your Rails application. An important thing is that if you just want to change one option then use After you’ve got the processor configured you just need to start it up. On any POSIX system you do:
But on Windows you need to do:
After that you can check the log/scgi.log to see if it’s listening and then move to configuring you web server of choice. Additional CommandsThe following is a list of the available
Cluster ManagementIn the previous version there was a feature called simple clustering. This feature
is currently removed until I can nail down some stability issues. Instead I’ve created
a simple way to setup clustering using the To configure three children to run in a cluster is pretty easy from the SRR perspective:
This will create a series of
Which just says, “Force the processor defined in config/scgi-0.yaml to stop now.” Once you’ve configured your processors you can start them all with:
This will start all of the processors up for you to run. An important thing to know is that they listen on ports starting at 9999 and going up from there. So these three would listen on 9999, 10000, 10001. The control protocol will then listen on ports 1000 lower than this: 8999, 9000, 9001. Make sure you use the -p option to change how this is done, or just edit the configs directly if you need something truly odd. Once the cluster is up you have all of the previous commands available. If you need
to know which ones are running, then look for the The only difficult part at this point is configuring your web server to access the cluster on all the different ports. Refer to the configuration documentation for you web server for more information on this. Configuring Web ServerThere are three pages of information for your particular web server configuration with SCGI: These configurations are mostly just simple ones based on borrowed information from others. The Lighttpd configuration is the one I use the most, and was given to me by Jan the Lighttpd as the option. Also look in the source package Testing It All OutWell, hopefully you have something you want to try out, so hit the web server at a URI that Rails will answer and see if it works. Graceful Restart And StatusSo you’ve got this massive banking application running that must always work and never
lose a user’s request. In addition to this you’re a cowboy developer who insists on restarting
production systems at will, exerting your power over your customers like Zues over the ancient world.
It’s your code dammit and you have the need- Ok, first off you’re an idiot. You must plan your upgrades if you want to keep your customers. Developers like you piss me off to no end. Your myopic view of the whole operation only means you’re too stupid to take your ass out of your little chair in your little cubicle, march it down the hallway, and tell the other people on your team that you’re going to destroy the world. What would be optimal is if you could make sure you do the changes and restarts on a planned schedule that involves all parties agreeing that the system will go down, what will change, and how to back it out. But, hey, I just write software right? What the hell do I know? Since you’re going to want to shutdown and restart your systems at will anyway to make up for your lack of planning, here’s how you can do it “gracefully”. You should be seriously warned that you should never depend on this being 100% flawless, and anyone telling you their “graceful restart” will never lose a request is full of shit. It’s pretty easy to do a graceful restart:
And with the cluster tool:
If any of the processors seem to get jammed up then you’ll need to restart them directly with their individual config file:
You should then watch the With the StoppingStopping is pretty easy:
And you can do the -f option to force it. The same is true for the The /busy.html RedirectOne questionable feature is the /busy.html file redirects. Whenever the server is overloaded (based on the -m (maxconns) option) or in the process of a graceful shutdown/restart it will send all new requests to /busy.html. You should create this page so that people can see a friendly message rather than nothing. Under lighttpd they will even get an infinite redirect which is just lighttpd’s problem. The reason /busy.html was chosen rather than a 503 status (which is the correct status) is that lighttpd and Apache didn’t support passing back a 503 status to the client. They both scrubbed the status out and did their own thing, which ended up being a pretty nasty 500 message or worse. By redirecting to /busy.html you can give a nice message and let them try the request again. |