Unitech / Unitech/pm2

Why logs are being created by root?

Open
#5,829 0 comments 0 reactions 0 assignees View on GitHub

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?

Logs are being created by root, and thus I need sudo to run pm2 flush

ll /home/jfolpf/.pm2/logs/geoapi.pt-out-30.log
-rw-r--r-- 1 root root 3925 May 24 14:54 /home/jfolpf/.pm2/logs/geoapi.pt-out-30.log

How could we reproduce this issue?

pm2 flus <app> demands sudo

Supporting information

# Run the following commands
$ pm2 report


--- PM2 report ----------------------------------------------------------------
Date                 : Sat May 25 2024 16:03:41 GMT+0200 (Central European Summer Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.1.0
node version         : 14.15.0
node path            : not found
argv                 : /usr/local/bin/node,/usr/local/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : root
uid                  : 0
gid                  : 0
uptime               : 166968min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.1.0
node version         : 16.20.2
node path            : /usr/local/bin/pm2
argv                 : /usr/local/bin/node,/usr/local/bin/pm2,report
argv0                : node
user                 : jfolpf
uid                  : 1000
gid                  : 1000
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz
cpus nb              : 8
freemem              : 13949177856
totalmem             : 31615844352
home                 : /home/jfolpf
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬───────────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name                          │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼───────────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 2   │ autocosts.prod                │ default     │ 6.3.50  │ cluster │ 20763    │ 3h     │ 464  │ online    │ 0.5%     │ 195.2mb  │ jfolpf   │ disabled │
│ 3   │ autocosts.prod                │ default     │ 6.3.50  │ cluster │ 20774    │ 3h     │ 464  │ online    │ 0.6%     │ 191.0mb  │ jfolpf   │ disabled │
│ 4   │ autocosts.prod                │ default     │ 6.3.50  │ cluster │ 20801    │ 3h     │ 464  │ online    │ 0.5%     │ 192.2mb  │ jfolpf   │ disabled │
│ 5   │ autocosts.prod                │ default     │ 6.3.50  │ cluster │ 20807    │ 3h     │ 464  │ online    │ 0.4%     │ 190.7mb  │ jfolpf   │ disabled │
│ 0   │ bike-reporter                 │ default     │ 1.2.1   │ cluster │ 24340    │ 3M     │ 0    │ online    │ 0.3%     │ 38.8mb   │ jfolpf   │ disabled │
│ 1   │ bike-reporter                 │ default     │ 1.2.1   │ cluster │ 24342    │ 3M     │ 0    │ online    │ 0.3%     │ 37.9mb   │ jfolpf   │ disabled │
│ 6   │ form-for-parking-violation    │ default     │ N/A     │ cluster │ 24414    │ 3M     │ 0    │ online    │ 0.3%     │ 89.0mb   │ jfolpf   │ disabled │
│ 7   │ form-for-parking-violation    │ default     │ N/A     │ cluster │ 24421    │ 3M     │ 0    │ online    │ 0.7%     │ 58.9mb   │ jfolpf   │ disabled │
│ 30  │ geoapi.pt                     │ default     │ 1.0.4   │ cluster │ 3119     │ 25h    │ 4    │ online    │ 1.4%     │ 2.6gb    │ jfolpf   │ disabled │
│ 31  │ geoapi.pt                     │ default     │ 1.0.4   │ cluster │ 1923     │ 25h    │ 5    │ online    │ 2%       │ 2.5gb    │ jfolpf   │ disabled │
│ 32  │ geoapi.pt                     │ default     │ 1.0.4   │ cluster │ 1980     │ 25h    │ 3    │ online    │ 2.4%     │ 2.5gb    │ jfolpf   │ disabled │
│ 33  │ geoapi.pt                     │ default     │ 1.0.4   │ cluster │ 2465     │ 25h    │ 5    │ online    │ 2.2%     │ 2.5gb    │ jfolpf   │ disabled │
│ 8   │ in-my-district                │ default     │ 1.0.0   │ cluster │ 24428    │ 3M     │ 0    │ online    │ 0.3%     │ 49.1mb   │ jfolpf   │ disabled │
│ 9   │ in-my-district                │ default     │ 1.0.0   │ cluster │ 24434    │ 3M     │ 0    │ online    │ 0.3%     │ 46.6mb   │ jfolpf   │ disabled │
└─────┴───────────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/home/jfolpf/.pm2/pm2.log last 20 lines:
PM2        | 2024-05-25T12:30:05: PM2 log: App [autocosts.prod:_old_3] exited with code [0] via signal [SIGINT]
PM2        | 2024-05-25T12:30:05: PM2 log: App [autocosts.prod:_old_3] will restart in 200ms
PM2        | 2024-05-25T12:30:05: PM2 log: pid=15006 msg=process killed
PM2        | 2024-05-25T12:30:05: PM2 log: App [autocosts.prod:4] starting in -cluster mode-
PM2        | 2024-05-25T12:30:05: PM2 log: pid=15022 msg=process killed
PM2        | 2024-05-25T12:30:05: PM2 log: App [autocosts.prod:5] starting in -cluster mode-
PM2        | 2024-05-25T12:30:07: PM2 log: -reload- New worker listening
PM2        | 2024-05-25T12:30:07: PM2 log: Stopping app:autocosts.prod id:_old_4
PM2        | 2024-05-25T12:30:07: PM2 log: App [autocosts.prod:4] online
PM2        | 2024-05-25T12:30:07: PM2 log: -reload- New worker listening
PM2        | 2024-05-25T12:30:07: PM2 log: Stopping app:autocosts.prod id:_old_5
PM2        | 2024-05-25T12:30:07: PM2 log: App [autocosts.prod:5] online
PM2        | 2024-05-25T12:30:07: PM2 log: App name:autocosts.prod id:_old_4 disconnected
PM2        | 2024-05-25T12:30:07: PM2 log: App [autocosts.prod:_old_4] exited with code [0] via signal [SIGINT]
PM2        | 2024-05-25T12:30:07: PM2 log: App [autocosts.prod:_old_4] will restart in 200ms
PM2        | 2024-05-25T12:30:07: PM2 log: App name:autocosts.prod id:_old_5 disconnected
PM2        | 2024-05-25T12:30:07: PM2 log: App [autocosts.prod:_old_5] exited with code [0] via signal [SIGINT]
PM2        | 2024-05-25T12:30:07: PM2 log: App [autocosts.prod:_old_5] will restart in 200ms
PM2        | 2024-05-25T12:30:07: PM2 log: pid=15067 msg=process killed
PM2        | 2024-05-25T12:30:07: PM2 log: pid=15073 msg=process killed

Please copy/paste the above report in your issue on https://github.com/Unitech/pm2/issues

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

Start by reproducing pm2 flush <app> and reviewing the daemon and CLI details from pm2 report, especially the differing users and UIDs. Trace how the daemon creates and flushes logs in /home/jfolpf/.pm2/logs/; done means a non-root PM2 session can create and flush its logs without sudo.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.