Logrotate Tip
16 Apr 2013Just a quick tip: I keep a bunch of virtual hosts on my web server under /srv/<hostname>
, where
each virtual host has an htdocs
and a logs
subdirectory for static content and logs, respectively.
I want logrotate to catch and rotate those logs, and as it turns out, logrotate handles a stanza
like this exactly as you’d hope:
/srv/*/logs/*.log {
weekly
missingok
rotate 12
compress
delaycompress
notifempty
sharedscripts
postrotate
if [ -x /usr/sbin/invoke-rc.d ]; then \
invoke-rc.d lighttpd reopen-logs > /dev/null 2>&1; \
else \
/etc/init.d/lighttpd reopen-logs > /dev/null 2>&1; \
fi; \
endscript
}
One configuration stanza catches all of my virtual hosts, I don’t need to remember to change it when I add or remove them.