views:

1872

answers:

4

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.

+3  A: 

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. :)

Lars Westergren
Great, that approach ended up being the easiest all round. Ended up using plink.exe rather than SSH (being on windows).I've got some fixes for the capistrano issues I hit, and a couple of other bugs that I didn't fix. I'll submit them to capistrano :)
madlep
+2  A: 

Might be worth looking at 'Vlad the deployer' it adds remote_task to Rake allowing you to run tasks on a remote server. Personally however I prefer to have a standard Rake task on the server, ssh in and run that task - which would then do an svn checkout, make the WAR file, whatever...

Kris
+2  A: 

I would probably use Ant for this. After all, it's just another WAR file, right? I don't know which version of Tomcat you're using but version 4.1x comes with an Ant task for deploying to Tomcat.

John Topley
+2  A: 

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:

  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.

  1. 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.

Caleb Powell