History always repeats itself and sometimes that's good. Here's a second chance to be part of it: tmdtc.com

Sunday 14 December 2008

Capistrano deployment for Jetty-Rails

As I have developed the (soon to be available) UploadForMe application with Jruby on Rails, I have had to look at the best way to deploy it in production. In development mode, I was just running the script/server with Jruby, but I needed something better for production.

I had first tested the Glassfish approach of running an Java application server. And although it isn't hard at all, as illustrated by Charles Nutter in his post correctly titled "Zero to Production in 15 Minutes", it wasn't practical for me: just running Glasfish consumed 300MB of RAM and impossible to run on my development machine. So I had to look somewhere else.

That's how I found Jetty-Rails.The way to run your JRuby on rails apps is so simple I thought their documentation was lacking! But it is really as simple as installing the jetty_rails gem!

The only missing piece were recipes and scripts to start, stop and restart the application when deploying with Capistrano. It was a simple matter of writing 2 scripts and the Capistrano recipe, with some experimentation in between I must admit :-)

Anyway, here are the scripts. The pid of the running jerry_rails process is stored in the file shared/tmp/pids/jetty_rails.pid.



There's a config file shared by these 2 scripts, put in script/jetty_config:

Put this in config/deploy.rb:


The start recipe is overwritten to add the option :pty => true. Without that option the nohup command isn't effective.
Using the nohup command is needed because there's currently no way to send the process to the background as a daemon, nor to store the PID in a specific file. These scripts do both.

No comments: