Capistrano and Glassfish (now with Gem!)

As I mentioned a while ago over here, Glassfish can be managed without a problem from Capistrano. In that post, I also mentioned that Gem wouldn't work, because it couldn't daemonize itself yet.

 Well, gem 0.9.3 includes daemonization support, and I've finally gotten some time to go back and write capistrano recipes for gem. Just as before, I'll be working off of a standard deploy.rb, but you'll need to make a few changes. First, stick these into the top of your script.

set :context_root, "/"
set :jruby_location, "/home/jacob/jruby/"
set :gf_port, "3000"
set :environment, "production"
set :jruby_runtimes, "1"
set :jruby_min_runtimes, "1"
set :jruby_max_runtimes, "2"

 Of those, only jruby_location is really needed, since the rest of them can be persisted in the glassfish gem yml config file. For a capistrano deployment you might as well set them here, though, so that all the options you are using are in a central location. Now, we need some actual commands:

 namespace :gem do
    desc "Start Glassfish Gem from a shutdown state"
    task :cold do
        start
    end
    desc "Stop a server running Glassfish Gem"
    task :stop do
        run "kill -INT $(cat #{current_path}/capistrano-#{application})"  
    end
    desc "Starts a server running Glassfish Gem"
    task :start do
        run "#{jruby_location}bin/jruby -S glassfish --contextroot #{context_root} --port #{gf_port} --environment #{environment} --runtimes #{jruby_runtimes} --runtimes-min #{jruby_min_runtimes} --runtimes-max #{jruby_max_runtimes} -P #{current_path}/capistrano-#{application} --daemon #{release_path}"
    end
    desc "Restarts a server running Glassfish Gem"
    task :restart do
        stop
        start
    end
end
And now, everything should work, and cap gem:start will start your application running on the production-quality glassfish gem. Be warned that, like Capistrano, this will only work on Unix/linux operating systems (sorry, windows users).
Comments:

Jacob,

Your other post uses the "deploy" namespace rather than the "gem" namespace - you might want to do that here too.

Ikai

Posted by Ikai Lan on April 01, 2009 at 10:25 AM PDT #

Great post. Very helpful. Thanks a lot.

Posted by David Beckwith on July 19, 2009 at 08:02 PM PDT #

This post was very helpful for me too -- I just went through the setup process for GlassFish with a Sinatra app on JRuby. I tweaked the Capistrano recipe a bit to work with initscripts on Ubuntu (10.04) and documented the outcome in case anyone else is trying to do a similar thing:

http://paul.rosania.org/writings/geekery/jruby-deployment-with-glassfish-and-capistrano/

Posted by Paul Rosania on May 17, 2010 at 12:42 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Jacob Kessler

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today