Grace and Dignity

Posted on August 31, 2005, under apache, general.

It’s only taken me 4 weeks, but as of last week httpd-trunk now supports a graceful stop, in both the worker and prefork MPM’s (for now, anyway). Depending on the status of the 2.1.7 release as a beta, graceful-stop may even make it into Apache httpd 2.2.0. All depending on how soon that happens.

So, now it’s possible to do “apachectl graceful-stop” and httpd will stop listening on any ports (they will be available immediately for any other process) but continue serving any requests which were active at the time of shutdown.

The default behaviour is to wait indefinitely until all of the active requests have been served, but a new directive “GracefulShutdownTimeout” also allows the administrator to specify how many seconds httpd should wait for exiting even if all requests have not yet finished. This directive, and a small bit of other code actually came from years-old work of Ken Coar and Bill Stoddard.

All of which means when we next upgrade httpd on, we won’t have to kill hundreds of active downloads, some of which can take hours to serve (think ISO downloads from dial-up). And as you can imagine, that really annoys some of our users. Instead, it’ll just be a matter of;

make install
apachectl graceful-stop
apachectl start

Thanks to some of the same code, if an administrator wants to be really fancy, they can actually rewrite httpd.conf to listen on different port, say 81, and issue an “apachectl graceful” (restart) and httpd will immediately unlisten on whatever port it was originally listening on. Which means the admin can still monitor what is being downloaded via mod_status.

Update: The event MPM is also supported.

Leave a Comment