I am trying to get logrotate to work on my OpenResty server logs. My logrotate configuration file /etc/logrotate.d/openresty
should execute daily which is default behavior and I'm trying to run it manually with sudo logrotate -vfd /etc/logrotate.d/openresty
.
This is how I configured it:
/home/appname/logs/openresty/*.log /var/log/openresty/*.log {
su root root
size 100M
missingok
rotate 14
compress
delaycompress
notifempty
create 0660 root root
sharedscripts
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
run-parts /etc/logrotate.d/httpd-prerotate; \
fi \
endscript
}
But this is how my log directory (~/logs/openresty
) looks like:
total 1.3G
-rw-r----- 1 root root 1.2G Jul 23 09:41 access.log.1
-rw-r----- 1 www-data adm 154K Jul 13 11:43 access.log.2.gz
-rw-r----- 1 www-data adm 159M Jul 13 11:18 access.log.3.gz
-rw-r----- 1 root root 572K Oct 5 04:24 error.log
-rw-r----- 1 root root 62K Jul 23 02:52 error.log.1
-rw-r----- 1 www-data adm 12K Jul 13 10:55 error.log.2.gz
As you can see the main log file is way above the 100 MB limit and it's not splitting as it should. Also not sure why it's named access.log.1
instead of access.log
(which is how it's configured in the server).
When I run sudo logrotate -v /etc/logrotate.d/openresty
I get the following output:
reading config file /etc/logrotate.d/openresty
Handling 1 logs
rotating pattern: /home/appname/logs/openresty/*.log /var/log/openresty/*.log 104857600 bytes (14 rotations)
empty log files are not rotated, old logs are removed
considering log /home/appname/logs/openresty/error.log
log does not need rotating
considering log /var/log/openresty/access.log
log needs rotating
considering log /var/log/openresty/error.log
log does not need rotating
rotating log /var/log/openresty/access.log, log->rotateCount is 14
dateext suffix '-20201005'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
compressing log with: /bin/gzip
renaming /var/log/openresty/access.log.14.gz to /var/log/openresty/access.log.15.gz (rotatecount 14, logstart 1, i 14),
old log /var/log/openresty/access.log.14.gz does not exist
renaming /var/log/openresty/access.log.13.gz to /var/log/openresty/access.log.14.gz (rotatecount 14, logstart 1, i 13),
old log /var/log/openresty/access.log.13.gz does not exist
renaming /var/log/openresty/access.log.12.gz to /var/log/openresty/access.log.13.gz (rotatecount 14, logstart 1, i 12),
old log /var/log/openresty/access.log.12.gz does not exist
renaming /var/log/openresty/access.log.11.gz to /var/log/openresty/access.log.12.gz (rotatecount 14, logstart 1, i 11),
old log /var/log/openresty/access.log.11.gz does not exist
renaming /var/log/openresty/access.log.10.gz to /var/log/openresty/access.log.11.gz (rotatecount 14, logstart 1, i 10),
old log /var/log/openresty/access.log.10.gz does not exist
renaming /var/log/openresty/access.log.9.gz to /var/log/openresty/access.log.10.gz (rotatecount 14, logstart 1, i 9),
old log /var/log/openresty/access.log.9.gz does not exist
renaming /var/log/openresty/access.log.8.gz to /var/log/openresty/access.log.9.gz (rotatecount 14, logstart 1, i 8),
old log /var/log/openresty/access.log.8.gz does not exist
renaming /var/log/openresty/access.log.7.gz to /var/log/openresty/access.log.8.gz (rotatecount 14, logstart 1, i 7),
old log /var/log/openresty/access.log.7.gz does not exist
renaming /var/log/openresty/access.log.6.gz to /var/log/openresty/access.log.7.gz (rotatecount 14, logstart 1, i 6),
old log /var/log/openresty/access.log.6.gz does not exist
renaming /var/log/openresty/access.log.5.gz to /var/log/openresty/access.log.6.gz (rotatecount 14, logstart 1, i 5),
old log /var/log/openresty/access.log.5.gz does not exist
renaming /var/log/openresty/access.log.4.gz to /var/log/openresty/access.log.5.gz (rotatecount 14, logstart 1, i 4),
old log /var/log/openresty/access.log.4.gz does not exist
renaming /var/log/openresty/access.log.3.gz to /var/log/openresty/access.log.4.gz (rotatecount 14, logstart 1, i 3),
renaming /var/log/openresty/access.log.2.gz to /var/log/openresty/access.log.3.gz (rotatecount 14, logstart 1, i 2),
renaming /var/log/openresty/access.log.1.gz to /var/log/openresty/access.log.2.gz (rotatecount 14, logstart 1, i 1),
renaming /var/log/openresty/access.log.0.gz to /var/log/openresty/access.log.1.gz (rotatecount 14, logstart 1, i 0),
old log /var/log/openresty/access.log.0.gz does not exist
log /var/log/openresty/access.log.15.gz doesn't exist -- won't try to dispose of it
running prerotate script
renaming /var/log/openresty/access.log to /var/log/openresty/access.log.1
creating new /var/log/openresty/access.log mode = 0660 uid = 0 gid = 0
However absolutely nothing gets rotated on ~/logs/openresty
. It just ignores the whole thing.
And on /var/log/openresty
a new empty log access.log
gets created but the old one doesn't get split and is still over 100 MB:
total 379M
-rw-rw---- 1 root root 0 Oct 5 08:51 access.log
-rw-r----- 1 root root 366M Oct 5 08:53 access.log.1
-rw-r----- 1 root root 5.1M Jul 23 09:41 access.log.2.gz
-rw-r----- 1 www-data adm 8.0K Jul 13 11:42 access.log.3.gz
-rw-r----- 1 root root 8.2M Jul 13 11:18 access.log.4.gz
-rw-r----- 1 www-data adm 70K Oct 4 14:17 error.log
-rw-r----- 1 root root 948 Jun 26 10:24 error.log.1
Also for some reason the server keeps writing on access.log.1
instead of access.log
.