Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to deploy a JRuby on Rails application to Tomcat?

I'm looking at ways to deploy a Ruby on Rails app (running on JRuby) to a Tomcat instance for testing.

The tomcat instance is running on a Solaris server that I can SSH to. I've looked at using Capistrano, but there doesn't seem to be a lot out there about using it to deploy to Tomcat, or even about running it under JRuby, and I keep hitting bugs in Capistrano due to the Windows/JRuby environment my PC is running (yeah, it's corporate - not my choice, but I've got to live with it).

I'm using warble to build the .war file, and the app deploys and runs fine once I manually copy it up and deploy it. I'm wanting something easier and more automated to actually get it there.

Anyone done this before? Documentation on the web seems pretty thin.

like image 616
madlep Avatar asked Sep 29 '08 05:09

madlep


2 Answers

I am running a Rails project using JRuby and deploying to a Tomcat server. I have chosen to deploy with Capistrano because it automates just about everything. I had to make a few minor modifications to Capistrano's deployment lifecycle in order to get it to run on Tomcat:

Step 1: I created a warble task to be run on the server after Capistrano updates the code:

desc "Run the warble command to deploy the site"
namespace(:deploy) do
  task :warble do
    run ". ~/.profile;cd #{release_path};warble"
  end
end

And hooked it into Capistrano lifecycle using:

after 'deploy:update_code', 'deploy:warble'

My Tomcat server has a symlink pointing to the #{release_path}/tmp/war directory created by warble. If you don't like this, you can easily modify the warble task to move the war file into the Tomcat directory instead.

Step 2: I overrode the deploy:start and deploy:stop tasks so that they kick off the Tomcat server instead of a Mongrel server:

desc "Starts the Tomcat Server"
namespace(:deploy) do
  task :start do
    sudo "#{tomcat_home}/bin/startup.sh"
  end
end

desc "Shutdown the Tomcat Server"
namespace(:deploy) do
  task :stop do
    sudo "#{tomcat_home}/bin/shutdown.sh"
  end
end

I run Capistrano tasks using MRI rather than the JRuby interpreter.

like image 162
Caleb Powell Avatar answered Oct 19 '22 05:10

Caleb Powell


I don't have much experience on this, so I don't know if I can give you the BEST way, but if Capistrano doesn't work, and you can't have a separate MRI install just to run it, you have just a few alternatives left:

Try running plain Rake and write your own deployment target: http://www.gra2.com/article.php/deploy-ruby-on-rails-applications-rake

Or use Ant or Maven.

Or if it just ONE server you have to deploy to, you could just hack together two Ruby scripts - one that listens on the server for shutdown/startup requests, and one local that you run to: Send shutdown, scp over the file, send startup.

By the way, have you submitted any integration bugs you find with Capistrano to the JRuby team? I'm sure they'd be happy to have any contribution. :)

like image 37
Lars Westergren Avatar answered Oct 19 '22 06:10

Lars Westergren