Logrotate Removing Logs

Issues related to applications and software problems
Post Reply
dcrdev
Posts: 68
Joined: 2015/10/25 23:42:17

Logrotate Removing Logs

Post by dcrdev » 2018/01/12 19:08:35

I'm trying to set up a custom logrotate config for some Apache virtualhost logs, but logrotate is creating the new empty log files and the old ones ares nowhere to be found. I ran find on the entire filesystem and they simply don't exist - can anyone help:

Code: Select all

cat /etc/logrotate.d/custom_httpd
/storage/WWW/*/*log {
    su root group
    missingok
    notifempty
    sharedscripts
    delaycompress
    postrotate
	/bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
    endscript
}

Code: Select all

logrotate -df /etc/logrotate.d/custom_httpd
[root@hostname logrotate.d]# logrotate -fd /etc/logrotate.d/custom_httpd
reading config file /etc/logrotate.d/custom_httpd
Allocating hash table for state file, size 15360 B

Handling 1 logs

rotating pattern: /storage/WWW/cloud.domain.com/log/*log  forced from command line (no old logs will be kept)
empty log files are not rotated, old logs are removed
considering log /storage/WWW/cloud.domain.com/log/access_log
  log needs rotating
considering log /storage/WWW/cloud.domain.com/log/error_log
  log does not need rotating (log is empty)considering log /storage/WWW/cloud.domain.com/log/ssl_access_log
  log needs rotating
considering log /storage/WWW/cloud.domain.com/log/ssl_error_log
  log does not need rotating (log is empty)considering log /storage/WWW/cloud.domain.com/log/ssl_request_log
  log needs rotating
rotating log /storage/WWW/cloud.domain.com/log/access_log, log->rotateCount is 0
dateext suffix '-20180112'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /storage/WWW/cloud.domain.com/log/access_log.1 to /storage/WWW/cloud.domain.com/log/access_log.2 (rotatecount 1, logstart 1, i 1), 
renaming /storage/WWW/cloud.domain.com/log/access_log.0 to /storage/WWW/cloud.domain.com/log/access_log.1 (rotatecount 1, logstart 1, i 0), 
rotating log /storage/WWW/cloud.domain.com/log/ssl_access_log, log->rotateCount is 0
dateext suffix '-20180112'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /storage/WWW/cloud.domain.com/log/ssl_access_log.1 to /storage/WWW/cloud.domain.com/log/ssl_access_log.2 (rotatecount 1, logstart 1, i 1), 
renaming /storage/WWW/cloud.domain.com/log/ssl_access_log.0 to /storage/WWW/cloud.domain.com/log/ssl_access_log.1 (rotatecount 1, logstart 1, i 0), 
rotating log /storage/WWW/cloud.domain.com/log/ssl_request_log, log->rotateCount is 0
dateext suffix '-20180112'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /storage/WWW/cloud.domain.com/log/ssl_request_log.1 to /storage/WWW/cloud.domain.com/log/ssl_request_log.2 (rotatecount 1, logstart 1, i 1), 
renaming /storage/WWW/cloud.domain.com/log/ssl_request_log.0 to /storage/WWW/cloud.domain.com/log/ssl_request_log.1 (rotatecount 1, logstart 1, i 0), 
fscreate context set to system_u:object_r:public_content_rw_t:s0
renaming /storage/WWW/cloud.domain.com/log/access_log to /storage/WWW/cloud.domain.com/log/access_log.1
disposeName will be /storage/WWW/cloud.domain.com/log/access_log.1
fscreate context set to system_u:object_r:public_content_rw_t:s0
renaming /storage/WWW/cloud.domain.com/log/ssl_access_log to /storage/WWW/cloud.domain.com/log/ssl_access_log.1
disposeName will be /storage/WWW/cloud.domain.com/log/ssl_access_log.1
fscreate context set to system_u:object_r:public_content_rw_t:s0
renaming /storage/WWW/cloud.domain.com/log/ssl_request_log to /storage/WWW/cloud.domain.com/log/ssl_request_log.1
disposeName will be /storage/WWW/cloud.domain.com/log/ssl_request_log.1
running postrotate script
running script with arg /storage/WWW/cloud.domain.com/log/*log : "
	/bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
"
removing old log /storage/WWW/cloud.domain.com/log/access_log.1
error: error opening /storage/WWW/cloud.domain.com/log/access_log.1: No such file or directory
Thought it might be selinux - so I temporarily put it into permissive mode, it did not help.

User avatar
avij
Forum Moderator
Posts: 2677
Joined: 2010/12/01 19:25:52
Location: Helsinki, Finland
Contact:

Re: Logrotate Removing Logs

Post by avij » 2018/01/12 19:50:49

man logrotate wrote: rotate count
Log files are rotated count times before being removed or mailed to the address specified in a mail directive. If count is 0, old versions are removed rather than rotated.
Try adding rotate 99 somewhere.

dcrdev
Posts: 68
Joined: 2015/10/25 23:42:17

Re: Logrotate Removing Logs

Post by dcrdev » 2018/01/13 00:04:13

Thanks that pointed me in the right direction -

So when logrotate is called via cron it passes /etc/logrotate.conf as the config, that file has an include on /etc/logrotate.d/* . The main config file /etc/logrotate.conf has the logrotate directive set to 4, when passing the configs from /etc/logrotate.d directly this directive does not get set.

So in actual fact the config above was fine all along, just needs to be called differently.

dcrdev
Posts: 68
Joined: 2015/10/25 23:42:17

Re: Logrotate Removing Logs

Post by dcrdev » 2018/01/25 09:29:00

So I can't get this to work -

I thought I had it before because I was able to run it manually, but it would appear this isn't working as part of the daily cron. I've tried running the exact line from /etc/cron.daily/logrotate and it works if I do it manually.

Furthermore all other logs are being rotated daily, there are no selinux denials and the cron log itself shows no errors.

Anything else I could try?

dcrdev
Posts: 68
Joined: 2015/10/25 23:42:17

Re: Logrotate Removing Logs

Post by dcrdev » 2018/01/26 16:16:34

This is the most infuriating thing ever - no way for me to debug this...

- The script + parameters called by cron, run fine manually.
- They don't work when called from cron.
- Cron log shows no errors.
- Logrotate status file shows no errors.

This is just nuts!

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

Re: Logrotate Removing Logs

Post by tunk » 2018/01/26 20:51:36

I have no experience with logrotate, but you may want to look at:
- instead of cron, see if a systemd timer works
- I think the run environment is different when run as cron and manually, i.e. environment variables like PATH may not have the same values

skatemple
Posts: 1
Joined: 2018/02/01 20:59:22

Re: Logrotate Removing Logs

Post by skatemple » 2018/02/01 21:02:46

Did you try adding the "-d" debug option on "/etc/cron.daily/logrotate" and saving the result to a .txt file?
Maybe there you could find some more info

Post Reply