Archive for August, 2005

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.

The War on Error

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

By commiting a stupid function prototype, which a compiler warning even showed up, I was reminded that I should be using a more efficient way to actually see errors in the middle of several hundred lines of regular output.

Last year, when we faced a similar problem, Brian Boyle and I wrote sexec, which is a tiny little wrapper program which colours stdout green and stderr red. Which means, I can do this;

cd httpd-trunk/
sexec make

and see this:

sexec in action

Through the magic of sexec, errors stick out a mile and are highlighted in red. Yes, on some platforms, gcc can provide colourised output, but this works with everything. See compiler errors, linker warning, make warnings, everything.

And where it comes in really useful is for automated builds or other automated tasks, because sexec can output XML. Here for example is what the error I missed, looks like when using:

-Wall -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes -Wno-multichar -Wnested-externs -Wno-long-long -Wunused-variable -Wunused-value

For another example of sexec in use, take a look at the status page, if you click on a project name you’ll get the rsync output from the last run, green output good, red bad.

It doesn’t do proper HTML/XML encoding just yet, eg “&”‘s are output as literal ampersands, not “&”, but it’s good enough as-is for most purposes, especially interactive use. I can leave a compile in the background and spot a warning a mile away.