Skip to content

Helpers to achieve Zero downtime Tomcat restart using plain Docker

Notifications You must be signed in to change notification settings

UnivParis1/tomcat-early-close-http-connector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Zero downtime Tomcat restart using plain Docker

With Docker, you can easily do things like:

  • rename container
docker container rename foo old-foo
  • tell tomcat to shutdown ASAP
docker kill --signal TERM old-foo
  • start new tomcat
docker run --network=host ...

This works easily for PHP-FPM. But what about Tomcat?

Related pages: https://iximiuz.com/en/posts/multiple-containers-same-port-reverse-proxy/ https://innovation.ebayinc.com/tech/engineering/zero-downtime-instant-deployment-and-rollback/

Issues to solve

Tomcat default behaviour

  • on startup:
    • bind HTTP port
    • start webapps
  • on shutdown:

Issues:

  • during "gracefulStopAwaitMillis", new requests are waiting and will be aborted

With Connector bindOnInit="false" (doc)

  • on startup:
    • start webapps
    • bind HTTP port
  • on shutdown:
    • unbind HTTP port
    • handle remaining requests
    • save sessions

Issues:

  • when the second tomcat is starting, the sessions file may not be available yet
  • during the second tomcat startup, the requests will return an error (HTTP 502 if rev proxied). This is especially bad for POST like requests

With EarlyCloseHttp11NioProtocol and EarlySessionsUnloadManager:

  • on startup:
    • bind HTTP port
    • start webapps
  • on shutdown:
    • save sessions
    • unbind HTTP port
    • handle remaining requests

Issues: none!

An alternative to EarlyCloseHttp11NioProtocol is to use unixDomainSocketPath (if you have a apache2/nginx on the same host) since you can easily rm it.

Usage

EarlyCloseHttp11NioProtocol

<Connector protocol="HTTP/1.1" ...

with

<Connector protocol="fr.univparis1.tomcat.EarlyCloseHttp11NioProtocol" ...

EarlySessionsUnloadManager

<Context>
    <Manager className="fr.univparis1.tomcat.EarlySessionsUnloadManager" pathname="/var/lib/sessions/" />
</Context>

It requires a listener:

<Server port="-1">
  <Listener className="fr.univparis1.tomcat.EarlySessionsUnloadListener" />
  ...

Compared to StandardManager, it features storing sessions in per-webapp files when "pathname" is a directory.

About

Helpers to achieve Zero downtime Tomcat restart using plain Docker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages