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

Endless files with copytruncate option in logrotate

· 52CE 我爱测

When I use logrotate with this configuration: /home/ubuntu/.pm2/logs/* { rotate 2 size 200k missingok notifempty compress delaycompress copytruncate create 0640 ubuntu ubuntu } My file (let's call it test ) doesn't get rotated un…

问题原文

原帖链接 · Andy · CC BY-SA 3.0

When I use logrotate with this configuration:

/home/ubuntu/.pm2/logs/* {
        rotate 2
        size 200k
        missingok
        notifempty
        compress
        delaycompress
        copytruncate
        create 0640 ubuntu ubuntu
}

My file (let's call it test) doesn't get rotated until it reaches 200k. Upon it reaching 200k it gets copytruncate-ed. I am left with test at 0k (correct!) and test.1 at > 200k.

The problem is that the next day I shall get test > 0k (growing correctly), test.1 at 0k and test.1.1 at > 200k. As days progress, I will eventually get an endless number of test.1.1.1.1... at 0k with the last one at > 200k created yesterday.

My original idea was to have two files, test at whatever size less than 200k and another, older, log file only.

I need to use copytruncate as if I don't the PM2 process is going to keep writing to the old log file.

What am I doing wrong?

已采纳解答

原帖链接 · Andy · CC BY-SA 3.0

For anybody who stumbles on a similar issue.

The problem is in this line:

/home/ubuntu/.pm2/logs/* {

In particular, the catch-all * should be swapped with *.log, or else, the rotated files (with extension .1, etc.) shall also be rotated upon the next rotation cycle.

This fixes the issue:

/home/ubuntu/.pm2/logs/*.log {

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

资料来源与适用范围

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

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

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