Unitech / Unitech/pm2

ecosystem can not correctly parse out_file but it can parse pid_file with same environment variable

Open
#5,565 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?

I need dynamicly log filenames, so I write an ecosystem.pm2.json file like this:

{
	'apps' : [
	  {
		'name': 'workplatform',
		'instances': 1,
		'script': 'npm',
		'args': 'start',
		'exec_mode': 'fork',
		'autorestart': true,
		'watch': false,
		'cwd': '/exports/apps',
		'out_file': `/exports/apps/logs/success.${process.env['HOSTNAME']}.log`,
		'pid_file': `/exports/apps/logs/pid.${process.env['HOSTNAME']}.log`,
		'error_file': `/exports/apps/logs/error.${process.env['HOSTNAME']}.log`,
	  }
	]
}

This result a file structure like this:

[root@platform01v frontend]# ls -l /opt/storage/k8s/workplatform/logs/
total 4852
-rw-r--r-- 1 root root   32304 Mar  3 16:21 error.workplatform-cluster-1.log
-rw-r--r-- 1 root root       2 Mar  3 15:55 pid.workplatform-cluster-0.log
-rw-r--r-- 1 root root       4 Mar  3 16:21 pid.workplatform-cluster-10.log
-rw-r--r-- 1 root root       2 Mar  3 15:47 pid.workplatform-cluster-11.log
-rw-r--r-- 1 root root       2 Mar  3 15:46 pid.workplatform-cluster-12.log
-rw-r--r-- 1 root root       2 Mar  3 15:54 pid.workplatform-cluster-1.log
-rw-r--r-- 1 root root       2 Mar  3 15:53 pid.workplatform-cluster-2.log
-rw-r--r-- 1 root root       2 Mar  3 15:52 pid.workplatform-cluster-3.log
-rw-r--r-- 1 root root       2 Mar  3 15:52 pid.workplatform-cluster-4.log
-rw-r--r-- 1 root root       2 Mar  3 15:51 pid.workplatform-cluster-5.log
-rw-r--r-- 1 root root       2 Mar  3 15:51 pid.workplatform-cluster-6.log
-rw-r--r-- 1 root root       2 Mar  3 15:50 pid.workplatform-cluster-7.log
-rw-r--r-- 1 root root       2 Mar  3 15:49 pid.workplatform-cluster-8.log
-rw-r--r-- 1 root root       2 Mar  3 15:48 pid.workplatform-cluster-9.log
-rw-r--r-- 1 root root 4870240 Mar  3 16:26 success.workplatform-cluster-1.log

I've checked the configuration with pm2 show command:

root@workplatform-cluster-10:/# pm2 show 1 
 Describing process with id 1 - name workplatform 
┌───────────────────┬───────────────────────────────────────────────────────┐
│ status            │ online                                                │
│ name              │ workplatform                                          │
│ namespace         │ default                                               │
│ version           │ N/A                                                   │
│ restarts          │ 1                                                     │
│ uptime            │ 7s                                                    │
│ script path       │ /usr/bin/npm                                          │
│ script args       │ start                                                 │
│ error log path    │ /exports/apps/logs/error.workplatform-cluster-1.log   │
│ out log path      │ /exports/apps/logs/success.workplatform-cluster-1.log │
│ pid path          │ /exports/apps/logs/pid.workplatform-cluster-10.log    │
│ interpreter       │ node                                                  │
│ interpreter args  │ N/A                                                   │
│ script id         │ 1                                                     │
│ exec cwd          │ /exports/apps                                         │
│ exec mode         │ fork_mode                                             │
│ node.js version   │ 10.24.0                                               │
│ node env          │ N/A                                                   │
│ watch & reload    │ ✘                                                     │
│ unstable restarts │ 0                                                     │
│ created at        │ 2023-03-03T08:21:31.637Z                              │
└───────────────────┴───────────────────────────────────────────────────────┘

PM2 only parsed a correct pid_file configuration, but left out_file & error_file wrong.

How could we reproduce this issue?

Start any node apps with ecosystem.pm2.json configuration above in a k8s cluster.

Then look at it's log output directory.

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Fri Mar 03 2023 08:30:23 GMT+0000 (Coordinated Universal Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.1.0
node version         : 10.24.0
node path            : not found
argv                 : /usr/bin/node,/usr/local/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : undefined
uid                  : 0
gid                  : 0
uptime               : 42min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.1.0
node version         : 10.24.0
node path            : /usr/local/bin/pm2
argv                 : /usr/bin/node,/usr/local/bin/pm2,report
argv0                : node
user                 : undefined
uid                  : 0
gid                  : 0
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz
cpus nb              : 8
freemem              : 12514279424
totalmem             : 16814288896
home                 : /root
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬──────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name             │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼──────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 1   │ workplatform     │ default     │ N/A     │ fork    │ 1054     │ 8m     │ 1    │ online    │ 0%       │ 58.7mb   │ root     │ disabled │
└─────┴──────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
Module
┌────┬──────────────────────────────┬───────────────┬──────────┬──────────┬──────┬──────────┬──────────┬──────────┐
│ id │ module                       │ version       │ pid      │ status   │ ↺    │ cpu      │ mem      │ user     │
├────┼──────────────────────────────┼───────────────┼──────────┼──────────┼──────┼──────────┼──────────┼──────────┤
│ 0  │ pm2-logrotate                │ 2.7.0         │ 25       │ online   │ 0    │ 0.2%     │ 63.1mb   │ root     │
└────┴──────────────────────────────┴───────────────┴──────────┴──────────┴──────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/root/.pm2/pm2.log last 20 lines:
PM2        | 2023-03-03T07:48:18: PM2 log: Process dump file    : /root/.pm2/dump.pm2
PM2        | 2023-03-03T07:48:18: PM2 log: Concurrent actions   : 2
PM2        | 2023-03-03T07:48:18: PM2 log: SIGTERM timeout      : 1600
PM2        | 2023-03-03T07:48:18: PM2 log: ===============================================================================
PM2        | 2023-03-03T07:48:18: PM2 log: App [pm2-logrotate:0] starting in -fork mode-
PM2        | 2023-03-03T07:48:18: PM2 log: App [pm2-logrotate:0] online
PM2        | 2023-03-03T07:48:18: PM2 log: App [workplatform:1] starting in -fork mode-
PM2        | 2023-03-03T07:48:18: PM2 log: App [workplatform:1] online
PM2        | 2023-03-03T07:58:07: PM2 log: Stopping app:workplatform id:1
PM2        | 2023-03-03T07:58:07: PM2 log: App [workplatform:1] exited with code [0] via signal [SIGINT]
PM2        | 2023-03-03T07:58:08: PM2 log: pid=35 msg=process killed
PM2        | 2023-03-03T07:58:41: PM2 log: Process 1 in a stopped status, starting it
PM2        | 2023-03-03T07:58:41: PM2 log: App [workplatform:1] starting in -fork mode-
PM2        | 2023-03-03T07:58:41: PM2 log: App [workplatform:1] online
PM2        | 2023-03-03T08:21:31: PM2 log: Process 1 in a stopped status, starting it
PM2        | 2023-03-03T08:21:31: PM2 log: Stopping app:workplatform id:1
PM2        | 2023-03-03T08:21:31: PM2 log: App [workplatform:1] exited with code [0] via signal [SIGINT]
PM2        | 2023-03-03T08:21:31: PM2 log: pid=438 msg=process killed
PM2        | 2023-03-03T08:21:31: PM2 log: App [workplatform:1] starting in -fork mode-
PM2        | 2023-03-03T08:21:31: PM2 log: App [workplatform:1] online

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 with the ecosystem.pm2.json configuration and reproduce the issue by running a Node app in a Kubernetes cluster, then inspect the generated log paths and the pm2 show output. Done means out_file and error_file resolve the HOSTNAME value consistently with pid_file.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.