2

I'm using:
Linux workdesk 3.16.0-31-generic #43~14.04.1-Ubuntu SMP Tue Mar 10 20:13:38 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Distributor ID: Ubuntu
Description: Ubuntu 14.04.2 LTS
Release: 14.04
Codename: trusty

logrotate 3.8.7-1ubuntu1 amd64

I trying to test behaviour of logrotate.

my conf file is:

/home/user/test/*.log {  
       daily  
       rotate 2  
       ifempty  
       su user user  
}  

ls /home/user/test/*.log outputs

/home/user/test/1.log

sudo logrotate -fv /etc/logrotate.d/r

outputs

reading config file /etc/logrotate.d/r

Handling 1 logs

rotating pattern: /home/user/test/*.log  forced from command line (2 rotations)  
empty log files are rotated, old logs are removed  
switching euid to 1000 and egid to 1000  
considering log /home/user/test/1.log  
  log needs rotating  
rotating log /home/user/test/1.log, log->rotateCount is 2  
dateext suffix '-20150327'  
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'  
renaming /home/user/test/1.log.2 to /home/user/test/1.log.3 (rotatecount 2, logstart 1, i 2),  
old log /home/user/test/1.log.2 does not exist  
renaming /home/user/test/1.log.1 to /home/user/test/1.log.2 (rotatecount 2, logstart 1, i 1),  
old log /home/user/test/1.log.1 does not exist  
renaming /home/user/test/1.log.0 to /home/user/test/1.log.1 (rotatecount 2, logstart 1, i 0),  
old log /home/user/test/1.log.0 does not exist  
log /home/user/test/1.log.3 doesn't exist -- won't try to dispose of it  
renaming /home/user/test/1.log to /home/user/test/1.log.1  
switching euid to 0 and egid to 0  

and after ls outputs

1.log.1  

and that's all

Can somebody explain the rotation of process?
1) What is "renaming /home/user/test/1.log.0 to /home/user/test/1.log.1"? If I have rotate count = 0
2) Where is 1.log file?
3) where is 1.log.0? As I understand it I should get only 1.log empty file and that's all

Elder Geek
  • 36,023
  • 25
  • 98
  • 183
Ilia
  • 21

1 Answers1

0

Your configuration file asks to rotate file *.log in /home/user/test every day even if file is empty and preserve two old file.

logrotate perform this action (as you can see in verbose output):

  • change user and group (due to su user user)
  • rename old logs if exist, starting from 1.log.2 (due to rotate 2)
  • remove 1.log.3 if exists (due to rotate 2)
  • rename current 1.log in 1.log.1
  • switch back user and group

So, as expected, at the end you found 1.log.1 that it should be 1.log file renamed.

Rename process prints error, but logrotate doesn't fail, if old log file doesn't exist, which hasn't been created yet in previous days.

If an application is writing in 1.log, after log rotation, it still writing in 1.log.1 because renaming file doesn't change file's inode. In this case you should force application to close current log file and reopen it, using its graceful restart.

Here is a useful link on how to do.

I'm not able to explain why logrotate tries to rename 1.log.0, it seems an implementation error that don't cause any bug.

Lety
  • 6,039
  • 2
  • 29
  • 37