Mongrel Falls Asleep

Jul 04, 2009 08:46PM

Windows, Mongrel, and an Apache proxy error!

Running a Rails application under Windows server is a far from the ideal deployment environment, but in some instances it must be done. In my case, a Windows 2003 box is the only server available to my employer. It was deployed before I arrived in my current position, and despite my best efforts and arguments to management, still remains.

The server is currently running 3 Rails applications that I've developed, each application with 4 mongrel instances running as services. Apache is used in the front end, and as far as I was aware, everything worked smoothly.

One day I arrived at work very early, 6am to be exact, and for some reason, received a 503 proxy error when checking one of the applications! Every application gave the same 503 Proxy error. Mongrel seemed to be going to sleep after several hours of inactivity. Google did not have any answers, either.

The Fix

Luckily the solution to this problem is simple enough, I would just set up a Windows "Scheduled Task" (cron job to all you Linux folk) to hit my mongrel instances every half hour. I haven't had the problem since. There is even an added benefit - the applications seem to respond even more quickly, probably due to my constant prodding at Mongrel.

The implementation is very hack-ish. My original thought was just to use Windows Telnet to make the requests, but that turned out to be much harder than I thought. The Windows version of Telnet does not seem to like being handled by a batch file. After 20 minutes, I gave up on Windows Telnet. Oh, it was easy enough to manually request the page from the server using Telnet, but for the life of me I could not get the batch file to do it. I'm too used to the Linux shell I suppose

Next, I tried PuTTY. Again, it was very easy to get it to work under the actual PuTTY client. But, getting Plink (PuTTY's command-line only version) to accomplish the same feat through a batch file was like pulling teeth.

For everyone not keeping score:

foreach($sites as $site) { $file = fopen( $site,"r"); if (!$file) { // Error opening site } else { // Site opened } fclose($file); }
Windows 2
Me 0

At this point, frustration and desperation kicked in. I turned to the quickest solution I could think of: Ruby!

mongrel_keepalive.bat

@echo off ruby < mongrel_keepalive.rb

mongrel_keepalive.rb

require 'net/http' sites = [ "http://127.0.0.1:5000/", "http://127.0.0.1:5001/", "http://127.0.0.1:5002/", "http://127.0.0.1:5003/", "http://127.0.0.1:5100/", "http://127.0.0.1:5101/", "http://127.0.0.1:5102/", "http://127.0.0.1:5103/", "http://127.0.0.1:5200/", "http://127.0.0.1:5201/", "http://127.0.0.1:5202/", "http://127.0.0.1:5203/" ] sites.each { |i| Net::HTTP.get( URI.parse( i ) ) }

-Butch