Adding a logrotation for your custom vhost apache logs
Maybe it will help someone.
–--------------------
The service logrotate is pretty straight forward. My logs are made by apache so there are some extra stuff that has to be included. This is not realy a script as much as a small directive file. This file is named mycustomfile and it is placed in the /etc/logrotate.d/ folder. I don't think it matters what the name of the file is. It will be added to what logrotate daemon does. The following example assumes you followed the directions on setting up your vhosts in the linode library.
/home/example_user/public/example.com/log/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 640 root root
sharedscripts
postrotate
if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
/etc/init.d/apache2 reload > /dev/null
fi
endscript
}
Meaning
The opening line shows the location of the logs with a wildcard statement.
weekly - Run Weekly
missingok - If the file isn't there for a sec, don't sweat it.
compress - compress the old files delaycompress - only compress the file after enough time elapses for apache to restart and start seeing the new file.
notifyempty - don't rotate it if it is empty create 640 root root - create the new file with 640 privs and root user and group
sharedscripts - run once for each
the last bit tells the apache service to restart so that it will start using the new log file.
(Everything about the naming of the files and backups should be automatic.)
Testing
You may want to run tests in verbose mode that actually don't run the log rotation. Remove the "d" which is test mode and replace that with a "f." F will FORCE running even if the scrip calls for running on certain days.
Test
logrotate -vd /etc/logrotate.d/yourcustomdirective
For Real
logrotate -vf /etc/logrotate.conf/yourcustomdirective