简体   繁体   English

将JRuby on Rails应用程序部署到Tomcat的最佳方法是什么?

[英]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. 我正在研究如何将Ruby on Rails应用程序(在JRuby上运行)部署到Tomcat实例进行测试。

The tomcat instance is running on a Solaris server that I can SSH to. tomcat实例正在我可以SSH到的Solaris服务器上运行。 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). 我已经看过使用Capistrano,但似乎没有太多关于使用它来部署到Tomcat,甚至在JRuby下运行它,并且由于Windows / JRuby环境我一直在Capistrano中遇到错误我的电脑正在运行(是的,这是公司 - 不是我的选择,但我必须忍受它)。

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. 我正在使用warble来构建.war文件,一旦我手动复制并部署它,应用程序就会部署并运行正常。 I'm wanting something easier and more automated to actually get it there. 我想要更简单,更自动的东西来实现它。

Anyone done this before? 有人这么做过吗? Documentation on the web seems pretty thin. 网络上的文档似乎很薄。

I am running a Rails project using JRuby and deploying to a Tomcat server. 我正在使用JRuby运行Rails项目并部署到Tomcat服务器。 I have chosen to deploy with Capistrano because it automates just about everything. 我选择使用Capistrano进行部署,因为它可以自动化所有内容。 I had to make a few minor modifications to Capistrano's deployment lifecycle in order to get it to run on Tomcat: 我不得不对Capistrano的部署生命周期进行一些小修改,以使其在Tomcat上运行:

Step 1: I created a warble task to be run on the server after Capistrano updates the code: 第1步:我在Capistrano更新代码后创建了一个在服务器上运行的warble任务:

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: 并使用以下方法将其挂钩到Capistrano生命周期:

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

My Tomcat server has a symlink pointing to the #{release_path}/tmp/war directory created by warble. 我的Tomcat服务器有一个符号链接,指向#{release_path}/tmp/war创建的#{release_path}/tmp/war目录。 If you don't like this, you can easily modify the warble task to move the war file into the Tomcat directory instead. 如果您不喜欢这样,可以轻松修改warble任务,将war文件移动到Tomcat目录中。

Step 2: I overrode the deploy:start and deploy:stop tasks so that they kick off the Tomcat server instead of a Mongrel server: 第2步:我覆盖deploy:startdeploy:stop任务,以便他们启动Tomcat服务器而不是Mongrel服务器:

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. 我使用MRI而不是JRuby解释器运行Capistrano任务。

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: 我对此没有多少经验,所以我不知道我是否可以给你最好的方法,但是如果Capistrano无法正常工作,并且你不能单独进行MRI安装就可以运行它,你有还剩下几个选择:

Try running plain Rake and write your own deployment target: http://www.gra2.com/article.php/deploy-ruby-on-rails-applications-rake 尝试运行普通Rake并编写自己的部署目标: http//www.gra2.com/article.php/deploy-ruby-on-rails-applications-rake

Or use Ant or Maven. 或者使用Ant或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. 或者,如果它只需要部署到一台服务器,您可以将两个Ruby脚本混合在一起 - 一个在服务器上侦听关闭/启动请求,另一个在您运行的本地:发送shutdown,scp over the file,send启动。

By the way, have you submitted any integration bugs you find with Capistrano to the JRuby team? 顺便问一下,你有没有向Capubrano提交任何整合错误给JRuby团队? I'm sure they'd be happy to have any contribution. 我相信他们会很乐意做出任何贡献。 :) :)

Might be worth looking at 'Vlad the deployer' it adds remote_task to Rake allowing you to run tasks on a remote server. 可能值得看看'Vlad the deployer'它将remote_task添加到Rake,允许您在远程服务器上运行任务。 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... 然而,我个人更喜欢在服务器上有一个标准的Rake任务,ssh并运行该任务 - 然后执行svn checkout,制作WAR文件,无论......

I would probably use Ant for this. 我可能会为此使用Ant。 After all, it's just another WAR file, right? 毕竟,它只是另一个WAR文件,对吧? I don't know which version of Tomcat you're using but version 4.1x comes with an Ant task for deploying to Tomcat . 我不知道您正在使用哪个版本的Tomcat,但版本4.1x 附带了用于部署到Tomcat的Ant任务

There's a few Capistrano recipes for deploying to Tomcat -- I built one into a gem called capistrano-tomcat . 有一些用于部署到Tomcat的Capistrano配方 - 我在一个名为capistrano-tomcat的宝石中构建了一个。 It takes a WAR you've built (probably with Warbler ) and deploys and starts a Tomcat instance on a remote server. 它需要你构建的WAR(可能使用Warbler )并在远程服务器上部署和启动Tomcat实例。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM