Log rotation doesn't follow user specification or $PM2_HOME
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
What's going wrong?
When running pm2 logrotate -u [username] as root, the default template will obey the current $HOME env var of the user. This "works" if you run sudo as the user that is running pm2, because the envvar doesn't update. But if you become interactive as root, then it will not work. Another case it does not work is via ansible deployments, without manually setting the $HOME variable
How could we reproduce this issue?
As root:
root@ip-1-1-1-1:~$ pm2 logrotate -u usernamez
root@ip-1-1-1-1:~$ cat /etc/logrotate.d/pm2-usernamez
/root/.pm2/pm2.log /root/.pm2/logs/* {
rotate 12
weekly
missingok
notifempty
compress
delaycompress
copytruncate
create 0640 usernamez usernamez
}
root@ip-1-1-1-1:~$ HOME=/home/usernamez pm2 logrotate -u usernamez
root@ip-1-1-1-1:~$ cat /etc/logrotate.d/pm2-usernamez
/home/usernamez/.pm2/pm2.log /home/usernamez/.pm2/logs/* {
rotate 12
weekly
missingok
notifempty
compress
delaycompress
copytruncate
create 0640 usernamez usernamez
}
The home dir path does not seem to be correct. I was thinking it should either obey $PM2_HOME (it does not, I tested it), or the -u <username> argument. Either way, $HOME does not seem to be the correct variable to key off of.
Supporting information
PM2 version: `pm2 -v`
2.4.5
Node version: `node -v`
v4.8.2
Windows? Mac? Linux?
Ubuntu 16.04.2
Let me know if you would like more information about anything.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing pm2 logrotate -u usernamez as root with and without HOME set, then trace the logrotate command entry point and how it selects the home directory. Done means the generated /etc/logrotate.d/pm2-usernamez paths use the target user's home or PM2_HOME, rather than root's $HOME, with behavior verified for the reported deployment cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100