giza: Giza White Mage (Default)
[personal profile] giza
As if I haven't been geeky enough today, I figured I'd post this too.

To start with, the machine I was working with had daemontools installed on it, and I wanted to have Apache make use of it. This would have the benefit of having yet another service be managed in the same way.

First trick was to start Apache from daemontools. That was easy enough. I created a directory called /serivce/apache and had the run script in it contain the following:

#!/bin/sh
exec 2>&1
exec /usr/local/apache2/bin/httpd -D NO_DETACH

The -D NO_DEATCH switch told the httpd program to stay in the foreground, so that when a signal is sent to the script to kill it, the signal really gets sent to httpd.

The other thing I wanted to do was have Apache's logging facility make use of the multilog program to handle logging. Otherwise, if I have n virtual servers running, 2n filehandles will be used, and that doesn't scale so well. So, I put the following lines into httpd.conf commented out the existing directives:

ErrorLog "| /usr/local/bin/setuidgid web /usr/local/bin/multilog t s1000000 n10 /var/log/httpd-error"
LogFormat "%v %p %h %u \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog "| /usr/local/bin/setuidgid web /usr/local/bin/multilog t s1000000 n10 /var/log/httpd-access" combined

These lines will log all errors to the /var/log/httpd-error/ and /var/log/httpd-access/ directories. multilog will also handle log rotation. In this case, after 1,000,000 bytes have been written, it will rotate the file and keep 20 older logfiles at most. The httpd-error/ and httpd-access/ directories will be created if they do not exist. Of course, if your webserver gets a lot more traffic than mine, you should probably make those numbers bigger.

Those of you who have been really observant may not that Apache won't be writing timestamps to the logfiles. That's because multilog handles that, in the Temps Atomique International format. Since the format looks a bit strange, it can be converted back to something humans can read with the tai64nlocal program, which comes with daemontools. For example, to view current webserver activity, you could use a command like this:

tail -f /var/log/httpd-access/current |tai64nlocal

To monitor the activity on a single virtual server, you could use something like this:

tail -f /var/log/httpd-access/current |tai64nlocal |grep hostname.domain

Have fun. :-)

P.S. I'd like to give credit to this article, which gave me the idea of using multilog with Apache!

[Edit: I added in the call to setuidgid, since we have no need to be logging things as root. :-) ]
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

giza: Giza White Mage (Default)
Douglas Muth

April 2012

S M T W T F S
1234567
891011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags