Pages

Sunday, 12 May 2013

Tomcat deployment script

So this weekend I deployed http://www.playerviewer.com (shameless attempt at self promotion!).  I've spent a lot of time with EC2 on Sonar / Jenkins boxes, but never deployed over Tomcat on it in production other than small tests.

One thing I found during the inital deployment that really started to be a constant theme...

stop tomcat, download war, delete old war folder, move war, start tomcat.

This started to become a pain, so I ended up just using a shell script.


So the maven process in my pom is to move my war to a directory, that then gets uploaded to http://www.mysite.com/deploy/ROOT.war and my shell script does the rest.
There are probably much nicer ways to do this such as using ant to ftp the script to the location for the shell script to download it, but it's not really that important.
Also - all the code from player viewer is available open source here

4 comments:

  1. It's possible to keep only:

    #!/bin/bash
    wget http://www.mysite.com/deploy/ROOT.war
    sudo mv ROOT.war /usr/share/tomcat7/webapps/

    ReplyDelete
    Replies
    1. The reason I try to avoid hot deployment is I'm never entirely convinced all the memory has been released. I'll hot deploy a number of times, say to ROOT#001.war, ROOT#002.war but I find restarting Tomcat is at least the most guaranteed way to know Tomcat has released fully.

      Delete
  2. why not just use the jenkins plugin?. it allows to select the artifact and your tomcat manager credentials

    ReplyDelete
    Replies
    1. This would mean the added overhead of having the Tomcat manager on the deployment as well as opening the ports in the security profile on EC2. This is a very plausible solution, but for the scale of the simple project I had, installing and configuring Jenkins, installing Tomcat manager, setting the security profile in EC2 just seemed a bit too much of a pain really.

      Thanks for your comment though, I'll consider that as an option in the future if I have a project large enough I need continuous integration.

      Delete