Jon's Tech Notes: Invoking a console from a deployed JRuby WAR file
2012-02-28 23:26
447 查看
Jon's Tech Notes: Invoking a console from a deployed JRuby WAR file
Bundled WAR deployments in JRuby are one of the great things about a JRuby app. There’s something satisfying about creating everything your awesome web application needs to run in a single file and pushing that out to your app servers. No crazy C bindings to install, it’s all right there (and no late nights figuring out why a gem built on linux won’t compile on Solaris).
While the war file deployments are great for running the app, one of the things I’ve missed was the ability to invoke a production console, run scripts or rake (easily). I’ve hacked around this in the past by deploying copy of the code to another directory on the production machine, and running JRuby out of a whole separate install on that machine. While it works OK, it’s not ideal, and I’ve bent over backwards in my capistrano scripts trying to keep that remote directory in sync on deployments.
Plus, isn’t everything the app needs to run already in deployed WAR file anyway? It turns out you can, you just have to set up some paths correctly and invoke the org.jruby.Main class directly.
After some trial and error, I’ve adopted this technique for invoking a production console in a Rails 3 app deployed with Warbler on JRuby, directly from the Glassfish autodeploy directory:
test-app.bash
This Gist brought to you by GitHub.
That’s a bash script that sets up the necessary environment variables to run a production console.
I’ll generally source that file, and then run this to get a production console:
To get your scripts in the production WAR, make sure to add this to your config/warble.rb file:
For migrations, I take a similar approach, but it requires a little bootstrap script to invoke rake. I place this in scripts/rake:
Then I make sure to include the Rakefile in my config/warble.rb, along with my migrations:
Then migrations can be run on a production machine by:
This can further be optimized by overriding the default deploy:migrate task in your capistrano script:
It’s not a perfect solution, but it seems to work pretty well. I’d love to hear what others have come up with for invoking scripts from deployed JRuby apps.
While the war file deployments are great for running the app, one of the things I’ve missed was the ability to invoke a production console, run scripts or rake (easily). I’ve hacked around this in the past by deploying copy of the code to another directory on the production machine, and running JRuby out of a whole separate install on that machine. While it works OK, it’s not ideal, and I’ve bent over backwards in my capistrano scripts trying to keep that remote directory in sync on deployments.
Plus, isn’t everything the app needs to run already in deployed WAR file anyway? It turns out you can, you just have to set up some paths correctly and invoke the org.jruby.Main class directly.
After some trial and error, I’ve adopted this technique for invoking a production console in a Rails 3 app deployed with Warbler on JRuby, directly from the Glassfish autodeploy directory:
export APP_HOME=/usr/local/glassfishv3/glassfish/domains/test-app/applications/test-app/WEB-INF export GEM_HOME=$APP_HOME/classpath:/META-INF/jruby.home/ export GEM_PATH=$APP_HOME/gems/ export APP_RUNNER="java -cp $APP_HOME/lib/jruby-core-1.5.3.jar:$APP_HOME/lib/jruby-stdlib-1.5.3.jar:$APP_HOME/lib/jffi-i386-SunOS.jar org.jruby.Main -r$APP_HOME/../META-INF/init" alias test-app="$APP_RUNNER"view raw
test-app.bash
This Gist brought to you by GitHub.
That’s a bash script that sets up the necessary environment variables to run a production console.
I’ll generally source that file, and then run this to get a production console:
source ~/test-app.bash cd $TEST_APP test-app script/rails c
To get your scripts in the production WAR, make sure to add this to your config/warble.rb file:
config.dirs = %w(app config lib log vendor tmp script db/migrate)
For migrations, I take a similar approach, but it requires a little bootstrap script to invoke rake. I place this in scripts/rake:
# Provides a way to run rake on deployed environments, straight out of the deployed war path require File.expand_path('../../config/application', __FILE__) require 'rake' Rake.application.run
Then I make sure to include the Rakefile in my config/warble.rb, along with my migrations:
# Application directories to be included in the webapp.
config.dirs = %w(app config lib log vendor tmp script db/migrate)
# Additional files/directories to include, above those in config.dirs
config.includes = FileList["Rakefile"]
Then migrations can be run on a production machine by:
cd $TEST_APP test-app script/rake db:migrate
This can further be optimized by overriding the default deploy:migrate task in your capistrano script:
namespace :deploy do desc "Runs the migrations using the deployed war" task :migrate, :roles => :db, :only => { :primary => true } do run "bash -c 'source /home/admin/test-app && cd $TEST_APP && $APP_RUNNER script/rake db:migrate'" end end
It’s not a perfect solution, but it seems to work pretty well. I’d love to hear what others have come up with for invoking scripts from deployed JRuby apps.
相关文章推荐
- 诡异的xen故障:xenconsole: Could not read tty from store: No such file or directory
- [导入]Processing A .aspx File From Console Window, Without Using IIS
- TECH: Getting a Stack Trace from a CORE file on Unix (Doc ID 1812.1)
- how-to-load-resource-from-jar-file-packaged-in-a-war-file
- TECH: Getting a Stack Trace from a CORE file on Unix (文档 ID 1812.1)
- This package (or one of its dependencies) contains an init.ps1 file and needs to be installed from the Package Manager Console.
- Extract audio from video file.
- How to: Reading an ini config file from a batch file
- Agile Testing - Google Tech Talk (notes)
- LoadFromFile SaveToFile
- Gains from a Team Tech Discussion Forum
- openfire源码在eclipse中运行,Failed to load admin-sidebar.xml file from Openfire classes
- VM8.0下安装遇到了问题“windows cannot read the<product key> setting from the unattend answer file”解决方法
- Unity3d 同步加载 Assetbundle 方法 AssetBundle.CreateFromFile
- DBMS_LOB.LOADFROMFILE
- Notes 发邮件的时候显示 "Error accessing User Dictionary File"
- Xcode8 missing file 报出 ”xx“is missing from working copy 的问题 解决方法汇总
- 使用OGG"Loading data from file to Replicat"的方法应该注意的问题:replicat进程是前台进程
- 解决rpm conflicts with file from package的两个方法
- 正确检查上传文件类型或者get mine type from file