10

I've been using Tomcat 8's Parallel Deployment as part of a zero-downtime continuous deployment setup for a while now.

When the test gauntlet has been run, the CI server automatically renames the .war file to application##{version-number}.war and copies the war to the /webapp folder. application##333 will coexist nicely with application##332.

The only problem that I'm encountering is that I have to manually undeploy the older applications once all traffic (new sessions) have automatically transitioned to the new one.

Does Tomcat have some built-in mechanism for saying "hey, when this service gets down to zero sessions, it should be removed"? Maybe some sort of "the last session has just expired" event that I can tap into.

If anyone else has automated this kind of application undeploy, I would love to hear about it. Thanks!

Martin Cron
  • 203
  • 2
  • 6

1 Answers1

10

You can configure Tomcat to remove the old applications. You need to add the undeployOldVersions attribute to the Host element and set it to true. You'll need to modify your host in server.xml to something like the following:

<Host undeployOldVersions="true" ...>
   ...
</Host>

See the Host documentation for details. In particular, this only works when automatic deployment is enabled.

Mark Thomas
  • 867
  • 5
  • 8
  • Under what version of Tomcat are you running? I have Tomcat 8.5.6 and this does not work. I have enabled FarmWarDeployer, and new releases are automatically deployed. However, after enabled undeployOldVersions on the Host tag, the older war files (and deployments) are not deleted. – Piko May 03 '17 at 18:42
  • Any progress on this with Tomcat 8? – JimmyD Mar 27 '18 at 09:52
  • 1
    The feature is implemented for Tomcat 8. If you are seeing issues when using FarmWarDeployer then open a bug, with steps to reproduce, so it gets looked at. – Mark Thomas Mar 27 '18 at 09:56