TriSano on Glassfish

Today, I'll be talking about deploying TriSano on Glassfish, as an example of how easy to deploy applications, even applications not written with Glassfish in mind, on both V3 prelude and glassfish gem 0.9.0.

 We'll be more or less following the TriSano installation instructions, available here. TriSano is an "open source, citizen-focused surveillance and outbreak management system for infectious disease". In its current form, it comes with scripts to generate a WAR file and deploy itself on Tomcat, but Glassfish removes the need for that. Lets begin!

The first step, of course, is to download TriSano from here. Even Glassfish can't let you run bits that you don't have. Unpack it somewhere convenient.

 Now, we're going to get all of the editing that we need to do out of the way. There are obviously some configuration differences between where it is now and how it needs to be for Glassfish to handle it well, but they are all minor configuration changes.

The first change that we need to make is to distro/config.yml. This is strictly optional, but if you want to use a different username and password from the default, you should change it here.

Next, we're going to go to distro/ This is the script that will give us all of the gems that we need to run TriSano (it comes bundled with Jruby 1.1.3). Add the following lines to the bottom of the file:

    jruby -S gem install --no-ri --no-rdoc rack
    jruby -S gem install --no-ri --no-rdoc glassfish
    jruby -S gem install --no-ri --no-rdoc activerecord-jdbcpostgresql-adapter
    jruby -S gem install --no-ri --no-rdoc rails -v=2.1.2
    jruby -S gem install --no-ri --no-rdoc haml
    jruby -S haml --rails /path/to/trisano/webapp

That will install the glassfish gem, the jdbc postgresql adapter, and rails 2.1.2. TriSano ships with rails 2.0.2, but glassfish requires rack support, which 2.0.2 doesn't have. That change also requires a new version of haml, since templates changed between versions.

Now, we get to go into the webapp folder and change a few configuration settings for the rails app.

First, in webapp/config, edit environment.rb and change

  RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION


  RAILS_GEM_VERSION = '2.1.2' unless defined? RAILS_GEM_VERSION

so that we actually use the new version of rails that we carefully set ourselves up to download.

Next, go into webapp/config/database.yml. Here, comment out all of the "adapter: postgresql" lines and uncomment the "adapter: jdbcpostgresql" lines, so we use the jdbc database adapter. If you wanted to use a non-default database username and password, you should change those here too. And lastly, if you are planning to use V3 prelude, you should make sure that the development database is set to be the same as the production database (which should be "trisano_production"). Prelude has a known issue where it doesn't correctly change the rails environment, and trying to start up without a database won't work at all.

And that's all the changes we need to make! Go ahead and install Jruby, install the required gems, create the postgresql users, configure the logging, and create or upgrade the database as per the TriSano instructions page. You do \*NOT\* need to package or deploy the app. That's the whole reason we're using glassfish, remember? Oh, and while you are installing the gems it will tell you that there is already a haml directory, and ask if you want to overwrite it. You do. I'll wait a bit for you to finish that.

Gem installation log

... We probably didn't need some of those gems. But, you can try TriSano out the normal way if you want to, I suppose...

Anyway, now that you've got that all set up, we're ready to deploy!

If you're using V3 prelude, you need to start up glassfish, using either the command line or the included asadmin tool. Instructions for that are available here. Don't forget to set the JRUBY_HOME property to the jruby included with TriSano.

Then, you just type "asadmin deploy /path/to/trisano/webapp". In a few seconds, asadmin will report that the deployment was sucessful, and you can now go view TriSano at localhost:8080/webapp.

asadmin deployment TriSano home page

TriSano Users page

Now, that was easy. But, you needed to run two commands (two whole commands!), and do a bunch of typing, and maybe wait for Glassfish to download. So, we'll move on to gem. You've already downloaded and installed gem, so you don't need to do any of that. Make sure that the trisano/lib/jruby/jruby-1.1.3/bin directory is in your path, navigate to trisano/webapp, and run "glassfish -e production". A few seconds later, it will report that it is done starting up and has sucessfully deployed. Just a tip, though. If you try to run both gem and V3 prelude at the same time, the planck bubble stablizers could conflict, unleashing a rip in the fabic of space-time and dooming us all. Or, you'll get a port conflict and it won't work. Either way, it's not a good idea, and won't work.

Gem deployment

And, you can go view TriSano at localhost:3000/

TriSano home page

TriSano users page

Now, you may have noticed that they look rather the same. That's because Glassfish gem is all of the parts of V3 prelude that you need to run Ruby-based applications, bundled up into a neat package and with some extra ease-of-use features thrown in on top. It's just as powerful at V3 prelude, as long as all you want to do is deploy Ruby apps. It even autodetects both Rails and Merb apps for you. And, it cuts the number of commands to deploy an app down to one, from two. A 50% reduction!

Now, wasn't that easier than hassling your way through WAR files and such?


Awesome Jacob. Thanks for figuring this out. We'll give a spin and look into using Glassfish as our default after we ship 1.0 of TriSano in January.

Posted by Mike Herrick on December 02, 2008 at 06:12 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed

Jacob Kessler


« August 2016