Sometimes you forget one crucial step…
When adding Apache vhosts on OpenSuSE and each vhost has it’s own set of log-files, then they will not be logrotated by default.
So you have to edit the configuration.
I’ve done it by copying the default apache2 logrotate configuration file for each vhost like this:
/etc/logrotate.d # cp apache2 apache2.vhost.##hostname##
Here ##hostname## is the name of the vhost.
Then I edited each file and replaced the generic log file names with the specific ones for each vhost.
There are only a few vhosts on my system so the manual job wasn’t so bad, but with a great number of vhosts you’d probably want to make this a template process beyond this:
function logrotate-add-apache2-vhost-file()
{
# $1 is the vhost name
## http://stackoverflow.com/questions/16790793/how-to-replace-strings-containing-slashes-with-sed/16790877#16790877
cat /etc/logrotate.d/apache2 | sed -r "s#/var/log/apache2/#/var/log/apache2/$1-#g" > /etc/logrotate.d/apache2.vhost.$1
git add /etc/logrotate.d/apache2.vhost.$1
}
This will then show in less what logrotate (which will output both to stderr and stdout, hence the 2>&1 redirect) would do on the next invocation:
logrotate -d /etc/logrotate.conf 2>&1 | less
And this is a very nice logrotate alias as well:
alias logrotate-show-status='echo "# systemctl list-timers --all" && systemctl list-timers --all && echo "# systemctl status logrotate.timer --full" && systemctl status logrotate.timer --full && echo "# journalctl -u logrotate" && journal
–jeroen





