2

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
  • 151
  • 7

1 Answers1

3

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 {
Andy
  • 151
  • 7