1754014 Members
4133 Online
108811 Solutions
New Discussion юеВ

Re: logrotate

 
Allanm
Super Advisor

logrotate


We need to rotate the logs for Apache when they reach close to 2GB. I know logrotate can do that but can I achieve this without restarting Apache.

Thanks,
Allan
4 REPLIES 4
Matti_Kurkela
Honored Contributor

Re: logrotate

Please read the description of the "copytruncate" directive from the logrotate man page. I have used it with success with Apache.

Of course, the caveat of the "copytruncate" applies: if Apache writes new entries to the log file exactly at the moment after the old log is copied away but before the log is truncated to zero size, those log entries may be lost.

MK
MK
Allanm
Super Advisor

Re: logrotate

Thanks for replying Matti, but can you share your /etc/logrotate.d script with me.

Thanks,
Allan.
Rick Retterer
Respected Contributor

Re: logrotate

From Apache.org:

Log Rotation

On even a moderately busy server, the quantity of information stored in the log files is very large. The access log file typically grows 1 MB or more per 10,000 requests. It will consequently be necessary to periodically rotate the log files by moving or deleting the existing logs. This cannot be done while the server is running, because Apache will continue writing to the old log file as long as it holds the file open. Instead, the server must be restarted after the log files are moved or deleted so that it will open new log files.

By using a graceful restart, the server can be instructed to open new log files without losing any existing or pending connections from clients. However, in order to accomplish this, the server must continue to write to the old log files while it finishes serving old requests. It is therefore necessary to wait for some time after the restart before doing any processing on the log files. A typical scenario that simply rotates the logs and compresses the old logs to save space is:

mv access_log access_log.old
mv error_log error_log.old
apachectl graceful
sleep 600
gzip access_log.old error_log.old

Rick Retterer

- Rick Retterer



Doug Davenport
Occasional Advisor

Re: logrotate

Try using the rotatelogs function built into Apache, see:

http://httpd.apache.org/docs/2.0/programs/rotatelogs.html

works great for us, you can rotate by time or size.