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

血红的双手。 提交于 2019-11-29 23:21:32

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

Caleb Powell

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.

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

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.

There's a few Capistrano recipes for deploying to Tomcat -- I built one into a gem called capistrano-tomcat. It takes a WAR you've built (probably with Warbler) and deploys and starts a Tomcat instance on a remote server.

The source is up on Github: http://github.com/rhunter/capistrano-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!