Unix

pm2 logrotate

ForceCore 2023. 1. 17. 13:27

pm2가 다 좋은데 logrotate만 없다 (?)

있는데 기본은 아니고 pm2 plugin이다.

그냥 시스템에 설치된 것으로 할지 pm2 plugin으로 할지 약간은 고민이 된다.

 

/etc/logrotate.d/pm2-ubuntu

/home/ubuntu/.pm2/logs/*.log {
    su ubuntu ubuntu
    daily
    rotate 10
    copytruncate
    delaycompress
    compress
    notifempty
    missingok
}

시스템 기본 logrotate로 한다면 위와 같이 하면 된다.. 하지만 시스템 파일을 건드려야 한다는 단점이 있다. 하지만 대부분 시스템에 있는 것을 활용하는 것이기도 하고, 세팅에 참고할 자료가 많음.

 

pm2 logrotate로 구글링하면 한국자료도 많이 나옴.

https://www.npmjs.com/package/pm2-logrotate

 

pm2-logrotate

Module to rotate logs of every pm2 application. Latest version: 2.7.0, last published: 3 years ago. Start using pm2-logrotate in your project by running `npm i pm2-logrotate`. There are 4 other projects in the npm registry using pm2-logrotate.

www.npmjs.com

저 플러그인을 설치해서 적절히 설정해 쓰면 된다.

pm2 install pm2-logrotate 로 설치.


pm2 set pm2-logrotate:max_size 1G

pm2 set pm2-logrotate:workerInterval 60

pm2 set pm2-logrotate:compress true

정도 세팅해둠.

 

pm2 conf 명령어로 나중에 설정할 수 있는 옵션이 뭐가 있었는지 다시 볼 수 있다.