less than 1 minute read

At uSwitch, several of our services are actually Clojure applications deployed with an embedded Jetty server(via the Ring adapter) which are managed via the standard Unix service interface.

For the business critical services, zero downtime is a fundamental requirement: here comes Jetty graceful shutdown.

Once the ready to be released uberjar is deployed, we signal the Unix service that wraps our Clojure application with a restart. As part of the shutdown process Jetty will immediately close the HTTP listener(freeing the used HTTP port and making it available to the newly deployed embedded instance) while it will still take care of completing the ongoing HTTP connections.

Ring 1.3.x and Jetty 7

If you are using Ring 1.3.x or older you are embedding Jetty 7. In that scenario this is the necessary configuration:

Ring 1.4.x and Jetty 9

with Jetty 9 the web container is now capable of keeping track of the open threads and to completely shut down itself once the threads are completed(rather than waiting for a fixed amount of time). With Ring 1.4.x and higher the code will then look like: