Rails rant software development

gem, rake, webricks hangs – resolved! (damn you windows)

You know you’re in for a fun day when you go to the code that you were working on yesterday and it stops working today.

In this case, I tried to start webrick to check my site, and the damn thing would not start. It would get as far as “=> Booting WEBrick…” and then hang. Ok, fine. Google a bit, maybe it’s the firewall? stop the firewall, no good.

Then, I tried to upgrade rails. ‘gem install’ hangs, before it says “upgrading source index”. Hrm. Must be something wrong with ruby. Try “gem list -r” which does not work on this machine but does work on my other workstation. Ok, got to be a ruby problem – upgrade ruby. no good. upgrade again. no good.

Then I uninstalled, rebooted, and reinstalled. “gem install” works! hooray! I install all the dependencies I need, and try to start webrick. Same bloody issue.

At this point, it’s fairly clear that it’s not a ruby or rails issue, it’s got to be a windows issue. I google for (out of desperation) “webrick hang” and I see, 4 down, a blog entry called WEBrick Server Hangs in Windows XP – have a look and it recommends running the following command to flush the Winsock Catalogue:

netsh winsock reset

And everything is fixed. Rake runs, webrick runs, gems still work. Bye bye 3 hours of my life. Thanks Windows. You’re a champ.

Rails software development

Ruby, SOAP4R and WSDL

For PeopleHub, we interface with a service provider to process payments with the banks. They, conveniently, have started to provide SOAP services, which is awesome. So, the question for me then, was how to integrate with them.

For some reason, I had trouble getting documentation on SOAP4R. The website itself is quite sparse, and there wasn’t much to see, until I found Ruby + SOAP4R + WSDL at Brendan, much kudos to you.

Basically, using SOAP without using the WSDL to generate code is a right pain the arse. Visual Studio does some nice intgrated stuff that generates code for you, as does the Apache stuff for Java. So, in ruby land, I was lost. Of course, Rails does have ActiveWebService and ActiveResource, but these were for producing services and using REST service from Rails respectively – no good for ad-hoc stuff.

The only thing I would caution the reader about is that although Ruby comes with a version of SOAP4R as part of the standard library, it DOES NOT come with the wsdl2ruby util from the distribution. Follow all of Brendan’s suggestions and you’ll be laughing.


Capistrano, Mongrel, and Mongrel_cluster

EDIT 2007-06-05: An updated version of this is up here

After my hiatus on posting it seems appropriate to get back into the meaty stuff…

Ever since I started using Debian (instead of FreeBSD) I’ve been having weird problems with my rails dispatch.fcgi processes multiplying in the night. Nothing shows up in the logs, but I spawn 2 externally of Lighttpd, and in the morning i’ve got 6 of the little blighters. Of course, at 20-30 meg a pop, the poor little Xen VPS isn’t too happy about that, so I have a nightly job that kills them all and restarts them. And then, 12 hours later, 4 more than I asked for are there. It seems to be a load issue, but I digress.

So ever since I noticed that I’ve been wanting to use Mongrel to run my Rails apps. For those not familiar with mongrel, it’s a Tomcat-style application host for rails apps that avoids (huzzah) the FCGI palaver that we ordinarily have to deal with. The problem was that according to mongrel, a USR2 signal should fully restart the daemon, and it does, but it’s a tiny little bit funny in a way that makes it totally painful to use with Capistrano for automated deployment.

You see, on restart, it doesn’t re-evaluate what the ./current symlink is pointing to. So when it’s restarted over a ./current that points to ./releases/2006xxxxxxxxx1 that’s fine, but on a redeployment through Cap when this symlink is repointed to ./releases/2006xxxxxxxxx2, the mongrel instance still points to ./releases/2006xxxxxxxxx1

So that’s not so good. Btw, Zed, you’re an awesome coder and I in no way mean you disrespect here. I’m just telling the problem I faced.

Along comes mongrel_cluster. Totally fixed the issue for me, and here’s how.

1. Install mongrel_cluster, and then (in ./current) run “mongrel_rails cluster::configure”

2. open the new ./config/mongrel_cluster.yml and edit the line that starts with “cwd:” like so:

  • change “cwd: /path/to/app/releases/2006xxxxxxxxx1” to “cwd: /path/to/app/current”
  • change the port to the first one you want for this cluster, and select how many you want (defauts to 2 which should be ‘enough’ for most cases)
  • change from “development” to “production”

3. Add the following tasks to your capistrano deploy.rb file

desc “The spinner task is used by :cold_deploy to start the application up”
task :spinner, :roles => :app do
send(run_method, “cd #{deploy_to}/#{current_dir} && mongrel_rails cluster::start”)

desc “Restart the mongrel cluster”
task :restart, :roles => :app do
send(run_method, “cd #{deploy_to}/#{current_dir} && mongrel_rails cluster::restart”)

4. Rejoice!

5. Before you do anything else, add to your crontab an @restart task to start the mongrel instances when your server comes up! Very important!

Now “rake remote:cold_deploy” and “rake remote:deploy” work for the mongrel cluster! I used the instructions on the mongrel site on how to integrate with lighttpd at but there are equally good Apache 2.2 docs out there (why Apache 2.2 isn’t available for Debian is anoher question entirely…)
Much kudos and thanks to Zed Shaw for the excellent mongrel server and to Bradley Taylor for mongrel_cluster. Oh, and Jamis Buck for Capistrano!



As my first post it seems appropriate to start with my main programming tool at the moment – Ruby On Rails. Over the years I’ve dealt with many of the most popular web programming languages including ASP and PHP, and while they are ‘ok,’ it’s just not the same as rails. The biggest thing that gets to me with languages like that is that it’s not hard per-se to get things done, it’s just that you need to do the same things over and over again. And god help you if you want to change the way you’ve been doing it… testing?? what’s that? In rails, it’s all built in, and you don’t have to muck about with the dreary boringness of the simple stuff like DB connections, it’s all there for you so you can get on with writing the app!

Pure genius.