Tuesday, September 8, 2009

Tips for autodeploying J2EE apps on Unix platforms

With a little bit of configuration you can have a nice autodeployment setup to save you time and remove potential errors.

For example this is something I can usually do after spending a few hours on the development infrastructure:

# from the build server, deploy the latest build for the specified project onto the 3 dev servers
deploy_build projectName trunk latest dev1 dev2 dev3

# deploy specified build for specified project
deploy_build projectName trunk build65 dev4

# deploy latest branch 2.0 onto specified server
deploy_build projectName 2.0 latest dev5


Also with a little bit more glue code those same commands can be run through your CI server interface, allowing one click deployment from the CI server GUI.

This is one way of achieving it, using standard Unix tools.


Fast deployment



First, take advantage of the autodeployment features supported by your application server (particularly in your development/test environment).

Autodeployment is typically triggered by you copying your WAR/EAR file into a particular directory on the target server:


On Unix, to copy your file from your CI server (you do use Continuous Integration, right?), you have several alternatives: share the disks through NFS, use scp, ... I prefer to use rsync. The reason?

  • First it takes less time. The EAR/WAR zip format is well handled by rsync's delta-transfer algorythm

  • Second, it is atomic. For those who have tried SCP, you might have noticed that the operation happens in place. If you have a network problem, you lose the old file and the new one isn't fully transfered. Worse, the app server will probably have tried loading the artifact before the copying operation is done. You end up with a failed restart, some errors in your logs, and some lost time. Rsync on the other hand will (by default) only move the file onto its target location once the full file has been transfered. This makes the operation atomic and you're sure the server won't fail because of an incomplete file



For rsync to work, you have to probably have to do the following:

  • install rsync and ssh on all servers (CI + target servers)

  • make sure the target file name doesn't change or you lose rsync!

  • optionally configure .ssh/options to make is even easier to connect to your servers

  • probably use ssh keys and agent, maybe even start ssh-agent before your CI server is started, that way you can use your deployment scripts as automatic post build operations. You might want to look into this setup and the related hudson startup scripts

  • automatically integrate the deployment script into your CI server GUI, or from the file system if the CI server is script friendly (like hudson)



Good luck and feel free to report your own successes !

No comments:

Post a Comment