【发布时间】:2015-09-18 06:17:20
【问题描述】:
在过去的几天里,我每天都会收到来自 cron 的 logrotate 任务的邮件:
/etc/cron.daily/logrotate:
gzip: stdin: 压缩时文件大小改变
我该如何解决?
谢谢, 吉安·马可。
【问题讨论】:
-
见here
在过去的几天里,我每天都会收到来自 cron 的 logrotate 任务的邮件:
/etc/cron.daily/logrotate:
gzip: stdin: 压缩时文件大小改变
我该如何解决?
谢谢, 吉安·马可。
【问题讨论】:
这是a blog post in French,它提供了一个解决方案。
英文版可以看this bug report。
总结一下:
首先,您必须在脚本/etc/cron.daily/logrotate 中添加--verbose 选项,以便在下次运行时获得更多信息,以确定导致问题的轮换日志。
#!/bin/sh
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate --verbose /etc/logrotate.conf`
接下来,您必须在 logrotate 配置中添加 delaycompress 选项。
和例子一样,我在 /etc/logrotate.d/nginx 中添加了 nginx 的 logrotate 配置:
/var/log/nginx/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 0640 www-data adm
sharedscripts
...
}
【讨论】:
delaycompress 只会在某些情况下为您提供帮助。看我的回答。
upstart 将在it notices that the file is deleted 时关闭(并重新打开)其日志文件。但是,如果您查看what gzip does,您会发现它在写入输出文件之前不会删除该文件。这意味着总是存在一种竞争条件,其中日志行可能会丢失正在写入的行日志gzipping。
您可以使用gzip --quiet 禁用警告,但这并不能掩盖您可能仍会丢失日志行的事实。
这意味着delaycompress 不是对此的通用修复。这是针对特定问题的特定修复。
真正的解决方案可能是delaycompress 和能够向进程发送信号的组合。它会使比赛条件在实践中消失(除非你每秒旋转多次:))。
【讨论】: