大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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 sys…

问题原文

原帖链接 · Lido · CC BY-SA 4.0

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

已采纳解答

原帖链接 · Server Fault · CC BY-SA 4.0

Try running logrotate by hand, in verbose mode, to see if anything sticks out. eg: logrotate -vf /etc/logrotate.conf. This will force a rotate of all your logs, and HUP all daemons configured. Just be aware it may cause intermittent unavailability of services.

If nothing turns up in the verbose output, start commenting out lines in /etc/logrotate.d/hiawatha until something works. Just a hunch, I suspect the postrotate lines are causing an issue so perhaps start with that.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-10-31)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。