Why isn't logrotate working on particular log files? Permissions and config the same. Debian Linux

I can't get my sites' access logs to rotate. The default log files are rotating fine, and permissions and logrotate conf file lines are the same as those, but they don't get touched for some reason. I can't find any errors in syslog or messages about it.

Rotating fine:

$ l /var/log/hiawatha/
-rw-r----- 1 www-data www-data  442604 Oct 31 06:03 access.log
-rw-r----- 1 www-data www-data  478300 Oct 28 06:12 access.log.1
-rw-r----- 1 www-data www-data    8295 Aug 26 05:24 access.log.10.gz
-rw-r----- 1 www-data www-data   12156 Aug 21 06:14 access.log.11.gz

Not rotating:

$ l /var/www/my_site/log/
-rw-r----- 1 www-data www-data 309498755 Oct 31 07:26 access.log
-rw-r----- 1 www-data www-data  14218318 Oct 31 05:00 error.log

Logrotate conf:

$ more /etc/logrotate.d/hiawatha 
/var/log/hiawatha/access.log {
    weekly
    compress
    delaycompress
    rotate 52
    missingok
    create 640 www-data www-data
    sharedscripts
    postrotate
        /usr/bin/killall -HUP hiawatha
    endscript
}

/var/www/my_site/log/*.log {
    weekly
    compress
    delaycompress
    rotate 52
    missingok
    create 640 www-data www-data
    sharedscripts
    postrotate
        /usr/bin/killall -HUP hiawatha
    endscript
}

Thanks.


More info after running the command manually with -vf as suggested by Server Fault below. I think the -f is what made things work because I'd run the following command:

sudo /usr/sbin/logrotate /etc/logrotate.conf

...before with no result. Note there's a line saying "Last rotated at 2018-10-31 06:00" even though I just ran the command (without the -f) seconds before, so somehow it is marking the log as rotated even though it wasn't rotated. But running with -f:

sudo /usr/sbin/logrotate -vf /etc/logrotate.conf

...produced the following output (trimmed to only show lines related to this issue). I don't see any indication as to why it wasn't working before, but hopefully it just needed to be forced the first time and it will work from now on:

rotating pattern: /var/www/my_site/log/*.log  forced from command line (52 rotations)
empty log files are rotated, old logs are removed
considering log /var/www/my_site/log/access.log
  Now: 2018-11-02 16:29
  Last rotated at 2018-10-31 06:00
  log needs rotating
{...}
considering log /var/www/my_site/log/error.log
  Now: 2018-11-02 16:29
  Last rotated at 2018-10-31 06:00
  log needs rotating
{...}
rotating log /var/www/my_site/log/access.log, log->rotateCount is 52
dateext suffix '-20181102'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
previous log /var/www/my_site/log/access.log.1 does not exist
renaming /var/www/my_site/log/access.log.52.gz to /var/www/my_site/log/access.log.53.gz (rotatecount 52, logstart 1, i 52), 
old log /var/www/my_site/log/access.log.52.gz does not exist
renaming /var/www/my_site/log/access.log.51.gz to /var/www/my_site/log/access.log.52.gz (rotatecount 52, logstart 1, i 51), 
{...}
log /var/www/my_site/log/error.log.53.gz doesn't exist -- won't try to dispose of it
renaming /var/www/my_site/log/access.log to /var/www/my_site/log/access.log.1
creating new /var/www/my_site/log/access.log mode = 0640 uid = 33 gid = 33
renaming /var/www/my_site/log/error.log to /var/www/my_site/log/error.log.1
creating new /var/www/my_site/log/error.log mode = 0640 uid = 33 gid = 33
running postrotate script
1
задан 2 November 2018 в 19:28
1 ответ

Попробуйте вручную запустить logrotate в подробном режиме, чтобы увидеть, не торчит ли что-нибудь. например: logrotate -vf /etc/logrotate.conf. Это вызовет принудительную ротацию всех ваших журналов и HUP всех настроенных демонов. Просто имейте в виду, что это может вызвать периодическую недоступность служб.

Если в подробном выводе ничего не появляется, начинайте комментировать строки в /etc/logrotate.d/hiawatha , пока что-то не сработает. Просто догадка, я подозреваю, что строки postrotate вызывают проблему, так что начнем с этого.

2
ответ дан 3 December 2019 в 20:11

Теги

Похожие вопросы