Bug 1419300 - not a bug: logrotate -d makes no changes to logs (and state file)
Summary: not a bug: logrotate -d makes no changes to logs (and state file)
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: logrotate
Version: 25
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Kamil Dudka
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-02-05 01:58 UTC by Todd Warner
Modified: 2017-02-06 07:52 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-02-06 07:52:16 UTC
Type: Bug


Attachments (Terms of Use)

Description Todd Warner 2017-02-05 01:58:49 UTC
Description of problem:

In order to test logrotate configurations, you use the commandline and the logrorate command directly, like this...

[root@XXX test]# /usr/sbin/logrotate -dvf /etc/logrotate.d/test

Well, it doesn't work.

Worse, logrotate *says* it worked without issue, when in fact it performed a no-op. If you run logrotate from the cron script... it does work just fine:
/etc/cron.daily/logrotate


This is maddening. Logrotate is 1000 years old. Heck, I am acquainted to two of the three original authors. Ugh. This needs to be fixed...


Version-Release number of selected component (if applicable):
logrotate-3.8.6-12.el7.x86_64
logrotate-3.9.2-5.fc24.x86_64
logrotate-3.10.0-1.fc25.x86_64



How reproducible:
Every time



##### Steps to Reproduce (the reproducer is trivial):

## SET THINGS UP...

# Become root
sudo su -

# Create a test directory and fake 1M debug.log in /var/log
cd /var/log
mkdir test
cd test
dd if=/dev/zero of=debug.log bs=1024 count=1024



# Let's look at that file...
[root@XXX test]# ll /var/log/test
total 1024
-rw-r--r--. 1 root root 1048576 Feb  4 20:20 debug.log
[root@XXX test]#



# Create logrotate config file to rotate this log file...
echo "/var/log/test/debug.log {
    rotate 5
    missingok
    notifempty
    compress
    maxsize 500k
    copytruncate
}" > /etc/logrotate.d/test




## DUPLICATE THE BUG...

[root@XXX test]# /usr/sbin/logrotate -dvf /etc/logrotate.d/test 

reading config file /etc/logrotate.d/test
Allocating hash table for state file, size 15360 B

Handling 1 logs

rotating pattern: /var/log/test/debug.log  forced from command line (5 rotations)
empty log files are not rotated, log files >= 512000 are rotated earlier, old logs are removed
considering log /var/log/test/debug.log
  log needs rotating
rotating log /var/log/test/debug.log, log->rotateCount is 5
dateext suffix '-20170204'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /var/log/test/debug.log.5.gz to /var/log/test/debug.log.6.gz (rotatecount 5, logstart 1, i 5), 
renaming /var/log/test/debug.log.4.gz to /var/log/test/debug.log.5.gz (rotatecount 5, logstart 1, i 4), 
renaming /var/log/test/debug.log.3.gz to /var/log/test/debug.log.4.gz (rotatecount 5, logstart 1, i 3), 
renaming /var/log/test/debug.log.2.gz to /var/log/test/debug.log.3.gz (rotatecount 5, logstart 1, i 2), 
renaming /var/log/test/debug.log.1.gz to /var/log/test/debug.log.2.gz (rotatecount 5, logstart 1, i 1), 
renaming /var/log/test/debug.log.0.gz to /var/log/test/debug.log.1.gz (rotatecount 5, logstart 1, i 0), 
copying /var/log/test/debug.log to /var/log/test/debug.log.1
truncating /var/log/test/debug.log
compressing log with: /bin/gzip
removing old log /var/log/test/debug.log.6.gz
error: error opening /var/log/test/debug.log.6.gz: No such file or directory
[root@XXX test]#


## Notice that there is only an error associated to it running through the rotation and erroring on that debug.log.6.gz? Weird. NONE of those files exist.

## Looking in that directory... all of the above *suggests* we had log files changed, copied, and truncated. But nothing changed...

[root@XXX test]# ll /var/log/test
total 1024
-rw-r--r--. 1 root root 1048576 Feb  4 20:20 debug.log
[root@XXX test]#


## Running logrotate from cron scripts *does* work:

[root@XXX test]# /etc/cron.daily/logrotate
[root@XXX test]# ll
total 4
-rw-r--r--. 1 root root    0 Feb  4 20:41 debug.log
-rw-r--r--. 1 root root 1051 Feb  4 20:20 debug.log-20170204.gz
[root@XXX test]# 


This makes testing hard. Please fix it. Thank you. -todd

PS. Note: Found a years old ubuntu bug that may be related...
https://bugs.launchpad.net/ubuntu/+source/logrotate/+bug/1278193

Special thanks for Will Darton of Navy Federal for helping me troubleshoot this. :)

Comment 1 Kamil Dudka 2017-02-06 07:52:16 UTC
(In reply to Todd Warner from comment #0)
> In order to test logrotate configurations, you use the commandline and the
> logrorate command directly, like this...
> 
> [root@XXX test]# /usr/sbin/logrotate -dvf /etc/logrotate.d/test

The above command works as expected but you forget to look at logrotate(8) man page to check meaning of the options you are using.  If you want logrotate to make any changes to logs and/or state file, just do not use the -d option.  This is clearly documented:

    -d, --debug
        Turns on debug mode and implies -v.  In debug mode, no changes will
        be made to the logs or to the logrotate state file.

To avoid further confusion (and creation of misleading bug reports), you should also check what the -f option does:

    -f, --force
        Tells logrotate to force the rotation, even if it doesn't think this
        is necessary.  Sometimes this is useful after adding new entries to
        a logrotate config file, or if old log files have been removed by
        hand, as the new files will be created, and logging will continue
        correctly.


Note You need to log in before you can comment on or make changes to this bug.