1

I just set up LogRotate on my RHEL6 server so that it rotates my custom Apache log files. However, it doesn't do anything when i try manually running it.

I expect it to rotate the log files "access.log" and "err.log". They have been there for a few days and need to be rotated.

Here is the output:

[root@pc1 httpd]# logrotate -d -f /etc/logrotate.d/apache
reading config file /etc/logrotate.d/apache
reading config info for /var/log/httpd/*log
/var/www/html/NSLogs/access.log
/var/www/html/NSErrorLogs/err.log


Handling 1 logs

rotating pattern: /var/log/httpd/*log
/var/www/html/NSLogs/access.log
/var/www/html/NSErrorLogs/err.log
 forced from command line (no old logs will be kept)
empty log files are rotated, old logs are removed
considering log /var/log/httpd/access_log
  log needs rotating
considering log /var/log/httpd/error_log
  log needs rotating
considering log /var/www/html/NSLogs/access.log
  log needs rotating
considering log /var/www/html/NSErrorLogs/err.log
  log needs rotating
rotating log /var/log/httpd/access_log, log->rotateCount is 0
dateext suffix '-20131023'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
fscreate context set to unconfined_u:object_r:httpd_log_t:s0
renaming /var/log/httpd/access_log to /var/log/httpd/access_log-20131023
disposeName will be /var/log/httpd/access_log-20131023.gz
running postrotate script
running script with arg /var/log/httpd/access_log: "
      /usr/bin/killall -HUP httpd
"
compressing log with: /bin/gzip
removing old log /var/log/httpd/access_log-20131023.gz
error: error opening /var/log/httpd/access_log-20131023.gz: No such file or directory
rotating log /var/log/httpd/error_log, log->rotateCount is 0
dateext suffix '-20131023'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
fscreate context set to unconfined_u:object_r:httpd_log_t:s0
renaming /var/log/httpd/error_log to /var/log/httpd/error_log-20131023
disposeName will be /var/log/httpd/error_log-20131023.gz
running postrotate script
running script with arg /var/log/httpd/error_log: "
      /usr/bin/killall -HUP httpd
"
compressing log with: /bin/gzip
removing old log /var/log/httpd/error_log-20131023.gz
error: error opening /var/log/httpd/error_log-20131023.gz: No such file or directory
rotating log /var/www/html/NSLogs/access.log, log->rotateCount is 0
dateext suffix '-20131023'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
fscreate context set to unconfined_u:object_r:httpd_sys_rw_content_t:s0
renaming /var/www/html/NSLogs/access.log to /var/www/html/NSLogs/access.log-20131023
disposeName will be /var/www/html/NSLogs/access.log-20131023.gz
running postrotate script
running script with arg /var/www/html/NSLogs/access.log: "
      /usr/bin/killall -HUP httpd
"
compressing log with: /bin/gzip
removing old log /var/www/html/NSLogs/access.log-20131023.gz
error: error opening /var/www/html/NSLogs/access.log-20131023.gz: No such file or directory
rotating log /var/www/html/NSErrorLogs/err.log, log->rotateCount is 0
dateext suffix '-20131023'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
fscreate context set to unconfined_u:object_r:httpd_sys_rw_content_t:s0
renaming /var/www/html/NSErrorLogs/err.log to /var/www/html/NSErrorLogs/err.log-20131023
disposeName will be /var/www/html/NSErrorLogs/err.log-20131023.gz
running postrotate script
running script with arg /var/www/html/NSErrorLogs/err.log: "
      /usr/bin/killall -HUP httpd
"
compressing log with: /bin/gzip
removing old log /var/www/html/NSErrorLogs/err.log-20131023.gz
error: error opening /var/www/html/NSErrorLogs/err.log-20131023.gz: No such file or directory
2
  • What did you expect it would do? I tried cleaning up the output but maybe you could edit and paste it again and now use the code {} button (after selecting the text). Then the line-breaks will be correct.
    – Rik
    Oct 23, 2013 at 15:33
  • Thanks, I re-pasted it. I expect it to rotate the log files "access.log" and "err.log". They have been there for a few days and need to be rotated.
    – blizz
    Oct 23, 2013 at 15:36

2 Answers 2

1

I'm not sure if this is the problem but if Apache is still running it might have a lock on those log-files. Maybe the /usr/bin/killall -HUP httpd does not kill Apache quick enough.

Try shutting Apache down first and see if that helps:

service httpd stop
logrotate -f /etc/logrotate.d/apache
service httpd start

If you don't start Apache with service you need to use the appropriate command.

BTW. my /etc/logrotate.d/httpd (which is your /etc/logrotate.d/apache) looks like this:

/var/log/httpd/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
        /bin/kill -USR1 `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}
3
  • I tried shutting down apache and then running logrotate but it had no effect
    – blizz
    Oct 23, 2013 at 16:04
  • 2
    You did remove the -d from your command? Because with -d nothing is done (only shown what will be done). It's just for debugging. Maybe you should add the content of your /etc/logrotate.d/apache to your question.
    – Rik
    Oct 23, 2013 at 16:11
  • I didn't realize the -d prevented it from actually doing anything. Thanks for that.
    – blizz
    Oct 23, 2013 at 16:24
1

I changed the format of the config file to the following and it seems to be working fine now.

/var/log/httpd/*log
/var/www/html/NSLogs/access.log
/var/www/html/NSErrorLogs/err.log
{
    copytruncate
    daily
    size 500M
    compress
    dateext
    maxage 60
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .