Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid temporary 404 errors during deployment with tomcat

Every time I copy OpenGrok/dist/source.war to /var/tomcat/webapps/, the tomcat generates blank error pages with 404 Not Found errors to my users, during a couple of seconds immediately after such copying.

HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
Content-Length: 0
Date: Tue, 02 Apr 2013 19:00:14 GMT
Connection: close

This is not acceptable. Am I not deploying correctly, by manually copying a .war file into a tomcat directory, or is it an OpenGrok bug of some sort? How do I ensure there's not a single visitor that'd be getting an undue 404 during the deployment process?

like image 933
cnst Avatar asked Sep 28 '26 00:09

cnst


1 Answers

Tomcat 7 has a feature called parallel deployments. Using this feature it is possible to have multiple instances of your app running under the same context path.

This blog post explains it nicely: http://www.javacodegeeks.com/2011/06/zero-downtime-deployment-and-rollback.html

To sum it up you need to manually version your wars when you add them to your appBase.

cp foo##001.war apache-tomcat-7/webapps/
cp foo##002.war apache-tomcat-7/webapps/

You may want to set undeployOldVersions and autoDeploy to true so that tomcat automatically deploys the app and removes the old version if it is no longer necessary. Check https://tomcat.apache.org/tomcat-7.0-doc/config/host.html for further info on tomcat's config.

The Version after the ## must be string comparable, so you can use e.g. a build number from your CI System but you may have to zero pad it.

There are a few things to look out for:

  • External resources need to be shareable, if you are using a database but your new versions needs a new schema you'll run into problems. Or if you open a TCP listener on a specific port it is also not shareable.
  • Caches, if your application uses internal caches they should be write through and expire quickly
  • The app must be undeployable
like image 136
Leonard Brünings Avatar answered Sep 29 '26 13:09

Leonard Brünings



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!