Logrotate is not working

General support questions
Post Reply
mehmetmirac
Posts: 11
Joined: 2022/03/31 06:37:43

Logrotate is not working

Post by mehmetmirac » 2022/05/10 14:14:03

Hi expert :)

I noticed that since April 5th on my Centos 7 server the logrotate process is not working.
Logrotate.PNG
Logrotate.PNG (14.03 KiB) Viewed 3892 times
The file /var/log/messages is 2.8GB in size. But it doesn't rotate daily. I searched many things but couldn't find why.

When I run the rotate process manually in debug mode, I get the following result.
Logrotate2.PNG
Logrotate2.PNG (63.88 KiB) Viewed 3892 times
Here it says rotate operation is required. But this process cannot be run on a daily basis.

What I don't understand is that while it was working properly, it suddenly stopped working.

I would be very grateful if you could help with this issue. Thanks in advance. :)

tunk
Posts: 1204
Joined: 2017/02/22 15:08:17

Re: Logrotate is not working

Post by tunk » 2022/05/10 14:28:01

No experience with logrotate, but I think I first would check
why the current file is very much bigger than the old ones.

User avatar
TrevorH
Site Admin
Posts: 33191
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Logrotate is not working

Post by TrevorH » 2022/05/10 15:59:37

Well, it would be much bigger than the old ones because it hasn't rotated in more than a month ;-)

Is the cron entry that invokes logrotate still in place and running? Check /var/log/cron for entries showing if it ran and /etc/cron.daily for the presence of the logrotate file which should look something like

-rwx------. 1 root root 219 Apr 1 2020 logrotate

and whose contents should be

Code: Select all

#!/bin/sh

/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

mehmetmirac
Posts: 11
Joined: 2022/03/31 06:37:43

Re: Logrotate is not working

Post by mehmetmirac » 2022/05/11 08:15:38

TrevorH wrote:
2022/05/10 15:59:37
Well, it would be much bigger than the old ones because it hasn't rotated in more than a month ;-)

Is the cron entry that invokes logrotate still in place and running? Check /var/log/cron for entries showing if it ran and /etc/cron.daily for the presence of the logrotate file which should look something like

-rwx------. 1 root root 219 Apr 1 2020 logrotate

and whose contents should be

Code: Select all

#!/bin/sh

/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
Yes, I have checked these files before. The outputs are as follows:
Cron_daily.PNG
Cron_daily.PNG (17.27 KiB) Viewed 3845 times
Cron2.PNG
Cron2.PNG (8.77 KiB) Viewed 3845 times
It's a really interesting situation. On some servers, the rotation process works fine, on others it does not. :D

User avatar
TrevorH
Site Admin
Posts: 33191
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Logrotate is not working

Post by TrevorH » 2022/05/11 08:17:30

Check the output from aureport -a for events around the time that the logrotate cron job runs.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

mehmetmirac
Posts: 11
Joined: 2022/03/31 06:37:43

Re: Logrotate is not working

Post by mehmetmirac » 2022/05/17 13:27:22

Hi :) I would like to share the solution in order to help others.

The problem is that the server we used before was RHEL6. In RHEL6, our /etc/logrotate.conf file was working fine when the permissions were 755.
logrotate755.PNG
logrotate755.PNG (1.92 KiB) Viewed 3747 times
RHEL6 Machine


But after we migrated our servers to CentOS7, this build stopped working, so I did some research. And I found that the problem is that logrotate allows to run on CentOS7 only with 0644 and 0444 permissions.
logrotate644.PNG
logrotate644.PNG (2.04 KiB) Viewed 3747 times
CENTOS7 Machine

As a result, Rhel6 can rotate with 755 permission, while Centos7 can only rotate with 644 and 444. If you try to rotate with another permission in Centos7 you will get this error:
logrotateError.PNG
logrotateError.PNG (2.95 KiB) Viewed 3747 times
Thanks :)

Post Reply