Capistrano and Glassfish

Well, sorry for not posting anything for a while. I've been doing stuff that, while very interesting to me, doesn't make for good blogging material. Making stuff faster, making the internal code of glassfish more beautiful, stuff like that. I could post a blog about the beauty of the new auto-detection system, but I'd probably be the only one to read it, since it's functionally equivelent to the old way.

 Anyway, I'm not actually here to apologize for not blogging for a while. What I am here for is to share a few glassfish Capistrano recipes. For those of you who don't know, Capistrano is a ruby-based remote management tool. The original use was to manage the packs of mongrels that rails required, but they've turned it into a very nice set of tools for general use. As a metaphore, rake is to single-server management what Capistrano is to multi-server management.

 So, the first thing to do (as usual) is to go install the gem:

gem install capistrano

 And then follow the setup instructions over at the Capistrano tutorials page. That should end up getting your application ready to deploy with Capistrano, if you were using a ruby-based server.

But, you're here because you want the ease of Capistrano and the power of Glassfish, so there are a few small changes that we need to make. Open config/deploy.rb.

We're going to override some of the built-in Capistrano methods so that we deploy using Glassfish, but we want to make sure that most of the functionality remains intact. Add the following to your deploy.rb:

set :context_root, "/" # You can obviously change this if you want to
set :glassfish_location, "/path/to/your/glassfish"
namespace :deploy do
    desc "Cold start Glassfish v3"
    task :cold do
        run "#{glassfish_location}/bin/asadmin start-domain domain1"
        start
    end

    desc "Stop a server running Glassfish v3"
    task :stop do
        run "#{glassfish_location}/bin/asadmin undeploy #{current_dir} || true"
        run "#{glassfish_location}/bin/asadmin stop-domain domain1"
    end
    desc "update and deploy to Glassfish v3"
    task :start do
        update
        run "#{glassfish_location}/bin/asadmin deploy --contextroot #{context_root} #{deploy_to}/#{current_dir}"
    end

    desc "restart the application"
    task :restart do

        run "#{glassfish_location}/bin/asadmin deploy --force=true --contextroot #{context_root} #{deploy_to}/#{current_dir}"
    end

    desc "Undeploy the application"
    task :undeploy do
        run "#{glassfish_location}/bin/asadmin undeploy #{current_dir}"
    end
end

Now, as usual, some caveats:

This is tested with Rails, but I've heard that there are some other tasks that may need to be modified to fully manage merb applications. Google disagrees about what exactly needs to be changed, but the changes in general seem fairly minor.

Since Glassfish can handle multiple rails applications at a time, you'll also have to make sure that if you are deploying multiple applications on the same Glassfish instance that you set the name of the "current" directory to something different for each of them (and the context roots, obviously), or there will be name conflicts.

This will also only work with Glassfish v3, not with Glassfish Gem. For it to work with gem, we'd need to have the gem be daemonizable, which we're working on (but it's not done yet, unfortunately). As soon as it is, though, I'll post gem recipes too.

Related to only working with Glassfish v3, all of the configuration options that you want will need to be specified in domain.xml on your remote servers. While that's something of a pain, I promise that it will be better once gem and Capistrano are working happily together.

So, there you are: Capistrano recipes for Glassfish. Happy deploying!


Comments:

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