1

This is my logrotate config:

/var/log/glusterfs/*.log /var/log/glusterfs/bricks/*.log /var/log/glusterfs/bricks/*.log.* {
  sharedscripts
  daily
  rotate 3
  copytruncate
  size 100M
  missingok
  compress
  delaycompress
  ifempty
  postrotate
  /usr/bin/killall -HUP glusterfs > /dev/null 2>&1 || true
  /usr/bin/killall -HUP glusterd > /dev/null 2>&1 || true
  endscript
}

This is the directory:

username@server:/var/log/glusterfs/bricks$ ll
total 405980
-rw------- 1 root root         0 Dec 23 00:05 be-data.log
-rw------- 1 root root         1 Dec 29 09:38 be.log.1
-rw------- 1 root root         0 Dec 25 11:24 nl.log
-rw------- 1 root root         0 Dec 29 09:49 nl.log.1.1
-rw------- 1 root root         0 Dec 29 09:50 nl.log.1.1.1
-rw------- 1 root root         0 Dec 29 09:55 nl.log.1.1.1.1
-rw------- 1 root root         0 Dec 29 09:55 nl.log.1.1.1.1.1
-rw------- 1 root root         0 Dec 29 09:55 nl.log.1.1.1.1.1.1
-rw------- 1 root root         0 Dec 29 09:55 nl.log.1.1.1.1.1.1.1
-rw------- 1 root root         0 Dec 29 09:55 nl.log.1.1.1.1.1.1.1.1
-rw------- 1 root root         0 Dec 29 10:08 nl.log.1.1.1.1.1.1.1.1.1
-rw------- 1 root root         0 Dec 29 10:08 nl.log.1.1.1.1.1.1.1.1.1.1
-rw------- 1 root root         0 Dec 29 10:08 nl.log.1.1.1.1.1.1.1.1.1.1.1
-rw------- 1 root root 368402432 Dec 29 10:08 nl.log.1.1.1.1.1.1.1.1.1.1.1.1
-rw------- 1 root root    610304 Dec 23 00:05 bo.log.1
-rw------- 1 root root    860160 Dec 23 00:05 bricks.log.1
-rw------- 1 root root    589824 Dec 23 00:05 other.log.1

What I can see:

  • Logs are not compressed
  • Logs are larger than 100MB
  • Count does not work
  • Empty log files are present, I do not want empty log files which are rotated

How should my config of logrotate be to solve all the issues described above?

4

In the configuration file, you have specified two patterns for the log files in the /var/log/glusterfs/bricks directory:

  1. *.log
  2. *.log.*

The second of these patterns will match any rotated log file. This is why you get files with seemingly endless .1 suffixes.

The logfiles are not compressed because you have delaycompress in the configuration. They will be compressed on the next rotation. Note that the first problem (rotation of already rotated logs due to the second pattern above) effectively disables any compression since all rotations are "the first" rotation.

The logfiles are rotated if they are larger than 100M, as per your configuration. There is one file larger than this. It's being rotated at every invocation and never compressed, due to the aforementioned problem with the second logfile pattern above.

There are empty logfiles. This is simply yet another effect of the faulty logfile matching pattern above. When a logfile is rotated, it's copied to name-of-file.log.1 and the original file, name-of-file.log, is truncated ("emptied"). Again, because of the *.log.* pattern in the configuration, the file name-of-file.log.1 will be copied to name-of-file.log.1.1 upon the next rotation, and the original name-of-file.log.1 will be truncated.

It's all working, but since the logfile pattern picks up not only the actual logfiles but the rotated logfiles as well, you end up with this mess.

  • Ah, thought it should be there. Guess it doesn't. – Kevin Dec 29 '16 at 9:59
-1

Viewing manpage of logrotate is free during this week!

   delaycompress
          Postpone compression of the previous log file to the next  rota‐
          tion  cycle.  This only has effect when used in combination with
          compress.  It can be used when some program cannot  be  told  to
          close  its logfile and thus might continue writing to the previ‐
          ous log file for some time.

   size size
          Log  files are rotated only if they grow bigger then size bytes.
          If size is followed by k, the size is assumed  to  be  in  kilo‐
          bytes.   If the M is used, the size is in megabytes, and if G is
          used, the size is in gigabytes. So size  100,  size  100k,  size
          100M and size 100G are all valid.

   ifempty
          Rotate  the  log  file  even  if  it  is  empty,  overriding the
          notifempty option (ifempty is the default).
  • ... This is exactly what I have configured. Why doesn't it do what I expect? – Kevin Dec 29 '16 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.