Unitech / Unitech/pm2

logrotate script does not reload logs

Open
#2,234 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

P3: Medium SYS: CLI T: Bug
Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

What happened?

The logrotate script installed by sudo pm2 logrotate -u <user> per http://pm2.keymetrics.io/docs/usage/log-management/#setting-up-a-native-logrotate will create log files that are not written to (they stay at 0 bytes).

What did you expect to happen?

I expect that log files created by logrotate can be written to by pm2.

Environment info

Operating System: Ubuntu 14.04.4
Pm2 version: 1.1.3
Node version: 0.10.45
Shell: bash

Steps to reproduce
  1. sudo pm2 logrotate -u <user>
  2. sudo logrotate -f /etc/logrotate.d/pm2-<user>
  3. ls -la ~/.pm2/logs
  4. Observe that the new log files stay at 0 bytes in size.
  5. pm2 reloadLogs
  6. ls -la ~/.pm2/logs
  7. Observe that the new log files are now logged to.
What have you tried?
  1. The solution by @sominlee74 in https://github.com/Unitech/pm2/issues/1469#issuecomment-215672049 fixed the issue entirely.

I believe that the logrotate script that gets generated just needs to have a couple more things added to it. Adding su <user> <user> and

postrotate
    su -c "pm2 reloadLogs" - <user>
endscript

fixed the issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect the implementation behind sudo pm2 logrotate -u <user> and the generated /etc/logrotate.d/pm2-<user> script. Reproduce the issue with sudo logrotate -f, then verify that rotated logs receive new output without running pm2 reloadLogs.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, javascript, nodejs
Domain
cli, devops
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.