Description of problem: I've got a nginx log dir which I need to be rotated regulary. But it doesn't work, despite the correct configs. /var/lib/logrotate.status doesn't have any mention of "nginx" word. SELinux is disabled. root@host [~]# cat /etc/logrotate.d/nginx /var/log/nginx/*log { missingok notifempty sharedscripts weekly postrotate /bin/kill -HUP \`cat /var/run/nginx.pid 2>/dev/null\` 2> /dev/null || true endscript } root@host [~]# cat /etc/logrotate.conf # see "man logrotate" for details # rotate log files weekly weekly # keep 4 weeks worth of backlogs rotate 4 # create new (empty) log files after rotating old ones create # uncomment this if you want your log files compressed #compress # RPM packages drop log rotation information into this directory include /etc/logrotate.d # no packages own wtmp -- we'll rotate them here /var/log/wtmp { monthly minsize 1M create 0664 root utmp rotate 1 } # system-specific logs may be also be configured here. root@host [~]# ls -l /var/log/nginx/ total 1900852 drwxr-xr-x 2 nginx nginx 4096 Mar 16 11:24 ./ drwxr-xr-x 16 root root 4096 Mar 16 14:16 ../ -rw-r--r-- 1 root root 0 Mar 16 11:24 access.log -rw-r--r-- 1 root root 17473 Mar 16 19:52 error.log -rw-r--r-- 1 root root 1750770945 Apr 9 07:14 vhost-access_log -rw-r--r-- 1 root root 2355064 Apr 9 07:14 vhost-default-access_log -rw-r--r-- 1 root root 132987 Apr 9 03:17 vhost-default-error_log -rw-r--r-- 1 root root 191258606 Apr 9 07:14 vhost-error_log root@host [~]# logrotate -d /etc/logrotate.conf [SKIPPED] rotating pattern: /var/log/nginx/*log weekly (4 rotations) empty log files are not rotated, old logs are removed considering log /var/log/nginx/access.log log does not need rotating considering log /var/log/nginx/error.log log does not need rotating considering log /var/log/nginx/vhost-access_log log does not need rotating considering log /var/log/nginx/vhost-default-access_log log does not need rotating considering log /var/log/nginx/vhost-default-error_log log does not need rotating considering log /var/log/nginx/vhost-error_log log does not need rotating not running postrotate script, since no logs were rotated [SKIPPED] Version-Release number of selected component (if applicable): 3.7.4-9
hello Yuri, I tried to reproduce your problem: you have specified "weekly" in the config, so the logs did rotate after I set the date and time in the system to more than a week after the files were created. If you want to rotate them sooner, change "weekly" to "daily" or set "minsize" instead, if you want to rotate after some specified size of the file. Did this help your problem? Maybe you should contact www.redhat.com/support, because the bugzilla is not meant to be a support tool
Daniel, thanks for replying. I've sorted this out. Turns out, logrotate won't pick up the newly added logrotate config for a directory until I do "logrotate -f", which adds logs' filename entries into logrotate.status file. I think it's still a bug. I mean, imagine you're installing a new RPM which carries a log rotation config file, like /etc/logrotate.d/nginx. The RPM install script would need to do the "logrotate -f /etc/logrotate.conf" thing without your permission, thus it will rotate all logs and that's probably not what you want, especially on a production machine. Maybe, logrotate should actually try to rotate logs, even if the "last rotation time" entries in logrotate.status file are missing ? What do you think ? Thanks!
when I was reproducing your bug, I did not run "logrotate -f", I have just set the date to be one week later and the log rotation happened even when nothing was in the status file - because it's "weekly", I just artificially "waited" one week and that was it: there is no minsize specified, so the log will rotate after first week: Even if there is no "-f", logrotate picked the file up. I see no bug here. Your "-f" just forced the rotation to happen earlier.
Well, I was trying it with "daily", too, and it didn't want to rotate them either. It would be nice if you could try to reproduce it with "daily" setting and no entries for that log in logrotate.status. From what I see in sources, "daily" just means "force the rotation of log despite anything". Thanks.
The problem is that if there is no entry for particular log in logrotate.status file, the first execution of "logrotate" command just adds that entry to logrotate.status (with current date) and never tries to rotate it. The second execution will actually rotate the log (if the rotate conditions are accomplished). By default, logrotate is called daily by cron. So if you create /etc/logrotate.d/nginx (and I presume you have "daily" there) today, today's logrotate call will just add entry into logrotate.status. Tomorrow's logrotate call will rotate the log. Then logs will be rotated regularly. So to sum it up, it needs two days to rotate the log, which should rotate daily, for the first time in this case. This can be fixed by running logrotate manually when you add new config file. Do you think this is your problem? I've tried to reproduce it, but except this problem it works for me.
Thanks, Jan, for clarifying this for me. Indeed, it works as expected on test machine, but I think, this behavior should be documented. Sadly, I don't have access to the server that I was talking about in my first message, and I remember clearly that I was running logrotate manually (with and without -d option) and it didn't add any /var/log/nginx/log_file_name entries into logrotate.status, which, for sure, caused such weird behavior. Thanks again for your time spent on this.
Well, I'm closing this bug because we're not able to reproduce this problem anymore. If it happens again and you will be able to reproduce it, please feel free to reopen this bug again.