Score:0

logrotate is not working correctly

gh flag

apache : 2.4.29

My requirement is that error_log needs to rotated and error_log needs to have the latest log, error_log.1 should have logs older than error_log and error_log.2 should have logs older than error_log.1 and so on. But the problem is after first rotation error_log becomes empty and error_log.1 has all the logs. After that only error_log.1 keeps getting filled with the logs and no further log file is created and error_log also stays empty. Here is the location where the log files are present:

[root@xxx]# ls -l
total 56
-rw-r--r-- 1 root root 37720 Jun 23 06:25 error_log
-rw-r--r-- 1 root root  4454 Jun 23 06:25 httpd.log

And here is the location for my conf file:

[root@xxx]# ls
test_apache_logrotate.conf  logrotate.rsyslog  
[root@xxx]# ```

And here are the contents of the conf file:
```/tmp/tools/error_log {
    su root root
    rotate 7
    size 300
    nocompress
    missingok
    notifempty
    create 640 root adm
    sharedscripts
    postrotate
            /usr/bin/pkill -HUP rsyslogd 2> /dev/null || true
    endscript
} ```


And then I run the logrotate on the conf file:
```[root@xxx]# /usr/sbin/logrotate -fv /etc/logrotate.d/test_apache_logrotate.conf
reading config file /etc/logrotate.d/test_apache_logrotate.conf
Reading state from file: /var/lib/logrotate.status
Allocating hash table for state file, size 64 entries
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state

Handling 1 logs

rotating pattern: /tmp/tools/error_log  forced from command line (7 rotations)
empty log files are not rotated, old logs are removed
considering log /tmp/tools/error_log
  Now: 2023-06-23 06:35
  Last rotated at 2023-06-23 06:19
  log needs rotating
rotating log /tmp/tools/error_log, log->rotateCount is 7
dateext suffix '-20230623'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
moving /tmp/tools/error_log.7 to /tmp/tools/error_log.8 (rotatecount 7, logstart 1, i 7),
old log /tmp/tools/error_log.7 does not exist
moving /tmp/tools/error_log.6 to /tmp/tools/error_log.7 (rotatecount 7, logstart 1, i 6),
old log /tmp/tools/error_log.6 does not exist
moving /tmp/tools/error_log.5 to /tmp/tools/error_log.6 (rotatecount 7, logstart 1, i 5),
old log /tmp/tools/error_log.5 does not exist
moving /tmp/tools/error_log.4 to /tmp/tools/error_log.5 (rotatecount 7, logstart 1, i 4),
old log /tmp/tools/error_log.4 does not exist
moving /tmp/tools/error_log.3 to /tmp/tools/error_log.4 (rotatecount 7, logstart 1, i 3),
old log /tmp/tools/error_log.3 does not exist
moving /tmp/tools/error_log.2 to /tmp/tools/error_log.3 (rotatecount 7, logstart 1, i 2),
old log /tmp/tools/error_log.2 does not exist
moving /tmp/tools/error_log.1 to /tmp/tools/error_log.2 (rotatecount 7, logstart 1, i 1),
old log /tmp/tools/error_log.1 does not exist
moving /tmp/tools/error_log.0 to /tmp/tools/error_log.1 (rotatecount 7, logstart 1, i 0),
old log /tmp/tools/error_log.0 does not exist
log /tmp/tools/error_log.8 doesn't exist -- won't try to dispose of it
moving /tmp/tools/error_log to /tmp/tools/error_log.1
creating new /tmp/tools/error_log mode = 0640 uid = 0 gid = 4
running postrotate script

And after the rotation:

[root@xxx]# ls -l
total 56
-rw-r----- 1 root adm      0 Jun 23 06:35 error_log
-rw-r--r-- 1 root root 37720 Jun 23 06:25 error_log.1
-rw-r--r-- 1 root root  4454 Jun 23 06:25 httpd.log

[root@xxx]#```

Thus it can be see that error_log is not having any contents.
Also after this I ran curl command from a client machine, after which the log contents changed:
```[root@xxx]# cd /tmp/tools/
[root@xxx]# ls -l
total 412
-rw-r----- 1 root adm       0 Jun 23 06:35 error_log
-rw-r--r-- 1 root root 398696 Jun 23 06:46 error_log.1
-rw-r--r-- 1 root root  11214 Jun 23 06:46 httpd.log ```
From the above it can seen that error_log.1 contents have changed.

I again give the logrotate on the conf file now:
```[root@xxx]# /usr/sbin/logrotate -fv /etc/logrotate.d/test_apache_logrotate.conf
reading config file /etc/logrotate.d/test_apache_logrotate.conf
Reading state from file: /var/lib/logrotate.status
Allocating hash table for state file, size 64 entries
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state

Handling 1 logs

rotating pattern: /tmp/tools/error_log  forced from command line (7 rotations)
empty log files are not rotated, old logs are removed
considering log /tmp/tools/error_log
  Now: 2023-06-23 06:50
  Last rotated at 2023-06-23 06:35
  log does not need rotating (log is empty)
not running postrotate script, since no logs were rotated ```
Now checking if the logs are rotated:
'''[root@xxx]# cd /tmp/tools/
[root@xxx]# ls -l
total 540
-rw-r----- 1 root adm       0 Jun 23 06:35 error_log
-rw-r--r-- 1 root root 524839 Jun 23 06:49 error_log.1
-rw-r--r-- 1 root root  13710 Jun 23 06:46 httpd.log

From the above we can see that the logs are not rotated.

/var/lib/logrotate.status: "/tmp/webtools/error_log" 2023-6-23-6:35:34

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.