Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.56k stars 2.62k forks source link

Critical error on compatibility with pm2 on automatically start service on system startup cases #5786

Open tranthiphu56 opened 8 months ago

tranthiphu56 commented 8 months ago
meow@meow-nv55s:~$ pm2 log server
[TAILING] Tailing last 15 lines for [server] process (change the value with --lines option)                                                   
/home/meow/.pm2/logs/server-out.log last 15 lines:
0|server   | {"level":30,"time":1710681182524,"pid":182275,"hostname":"meow-nv55s","msg":"Server listening at http://[::1]:3000"}
0|server   | {"level":30,"time":1710681182558,"pid":182275,"hostname":"meow-nv55s","msg":"Server listening at http://127.0.0.1:3000"}

/home/meow/.pm2/logs/server-error.log last 15 lines:
0|server   | /home/meow/Bản tải về/hello/node_modules/fastify/fastify.js:186
0|server   |       useSemicolonDelimiter: options.useSemicolonDelimiter ?? defaultInitOptions.useSemicolonDelimiter
0|server   |                                                             ^
0|server   | 
0|server   | SyntaxError: Unexpected token '?'
0|server   |     at wrapSafe (internal/modules/cjs/loader.js:915:16)
0|server   |     at Module._compile (internal/modules/cjs/loader.js:963:27)
0|server   |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
0|server   |     at Module.load (internal/modules/cjs/loader.js:863:32)
0|server   |     at Function.Module._load (internal/modules/cjs/loader.js:708:14)
0|server   |     at Module.require (internal/modules/cjs/loader.js:887:19)
0|server   |     at Module.Hook._require.Module.require (/home/meow/.local/share/fnm/node-versions/v20.11.1/installation/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39)
0|server   |     at require (internal/modules/cjs/helpers.js:74:18)
0|server   |     at Object.<anonymous> (/home/meow/Bản tải về/hello/server.js:7:17)
0|server   |     at Module._compile (internal/modules/cjs/loader.js:999:30)

0|server  | /home/meow/Bản tải về/hello/node_modules/fastify/fastify.js:186
0|server  |       useSemicolonDelimiter: options.useSemicolonDelimiter ?? defaultInitOptions.useSemicolonDelimiter
0|server  |                                                             ^
0|server  | SyntaxError: Unexpected token '?'
0|server  |     at wrapSafe (internal/modules/cjs/loader.js:915:16)
0|server  |     at Module._compile (internal/modules/cjs/loader.js:963:27)
0|server  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
0|server  |     at Module.load (internal/modules/cjs/loader.js:863:32)
0|server  |     at Function.Module._load (internal/modules/cjs/loader.js:708:14)
0|server  |     at Module.require (internal/modules/cjs/loader.js:887:19)
0|server  |     at Module.Hook._require.Module.require (/home/meow/.local/share/fnm/node-versions/v20.11.1/installation/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39)
0|server  |     at require (internal/modules/cjs/helpers.js:74:18)
0|server  |     at Object.<anonymous> (/home/meow/Bản tải về/hello/server.js:7:17)
0|server  |     at Module._compile (internal/modules/cjs/loader.js:999:30)
0|server  | /home/meow/Bản tải về/hello/node_modules/fastify/fastify.js:186
0|server  |       useSemicolonDelimiter: options.useSemicolonDelimiter ?? defaultInitOptions.useSemicolonDelimiter
0|server  |                                                             ^
0|server  | SyntaxError: Unexpected token '?'
0|server  |     at wrapSafe (internal/modules/cjs/loader.js:915:16)
0|server  |     at Module._compile (internal/modules/cjs/loader.js:963:27)
0|server  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
0|server  |     at Module.load (internal/modules/cjs/loader.js:863:32)
0|server  |     at Function.Module._load (internal/modules/cjs/loader.js:708:14)
0|server  |     at Module.require (internal/modules/cjs/loader.js:887:19)
0|server  |     at Module.Hook._require.Module.require (/home/meow/.local/share/fnm/node-versions/v20.11.1/installation/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39)
0|server  |     at require (internal/modules/cjs/helpers.js:74:18)
0|server  |     at Object.<anonymous> (/home/meow/Bản tải về/hello/server.js:7:17)
0|server  |     at Module._compile (internal/modules/cjs/loader.js:999:30)
^C
meow@meow-nv55s:~$ 

meow@meow-nv55s:~$ pm2 report

--- PM2 report ----------------------------------------------------------------
Date                 : Mon Mar 18 2024 13:39:20 GMT+0700 (Giờ Đông Dương)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.3.1
node version         : 12.22.9
node path            : not found
argv                 : /usr/bin/node,/home/meow/.local/share/fnm/node-versions/v20.11.1/installation/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : meow
uid                  : 1000
gid                  : 1001
uptime               : 13min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.3.1
node version         : 20.11.1
node path            : /run/user/1000/fnm_multishells/15399_1710743459875/bin/pm2
argv                 : /home/meow/.local/share/fnm/node-versions/v20.11.1/installation/bin/node,/run/user/1000/fnm_multishells/15399_1710743459875/bin/pm2,report
argv0                : node
user                 : meow
uid                  : 1000
gid                  : 1001
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : AMD A6-3400M APU with Radeon(tm) HD Graphics
cpus nb              : 4
freemem              : 2111475712
totalmem             : 5659095040
home                 : /home/meow
===============================================================================
--- PM2 list -----------------------------------------------
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐                                                               
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │                                                               
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤                                                               
│ 0  │ server             │ fork     │ 1122 │ online    │ 0%       │ 47.2mb   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘                                                               
===============================================================================
--- Daemon logs --------------------------------------------
/home/meow/.pm2/pm2.log last 20 lines:
PM2        | 2024-03-18T13:39:15: PM2 log: App [server:0] starting in -fork mode-
PM2        | 2024-03-18T13:39:15: PM2 log: App [server:0] online
PM2        | 2024-03-18T13:39:16: PM2 log: App [server:0] exited with code [1] via signal [SIGINT]
PM2        | 2024-03-18T13:39:16: PM2 log: App [server:0] starting in -fork mode-
PM2        | 2024-03-18T13:39:16: PM2 log: App [server:0] online
PM2        | 2024-03-18T13:39:17: PM2 log: App [server:0] exited with code [1] via signal [SIGINT]
PM2        | 2024-03-18T13:39:17: PM2 log: App [server:0] starting in -fork mode-
PM2        | 2024-03-18T13:39:17: PM2 log: App [server:0] online
PM2        | 2024-03-18T13:39:17: PM2 log: App [server:0] exited with code [1] via signal [SIGINT]
PM2        | 2024-03-18T13:39:17: PM2 log: App [server:0] starting in -fork mode-
PM2        | 2024-03-18T13:39:17: PM2 log: App [server:0] online
PM2        | 2024-03-18T13:39:18: PM2 log: App [server:0] exited with code [1] via signal [SIGINT]
PM2        | 2024-03-18T13:39:18: PM2 log: App [server:0] starting in -fork mode-
PM2        | 2024-03-18T13:39:18: PM2 log: App [server:0] online
PM2        | 2024-03-18T13:39:18: PM2 log: App [server:0] exited with code [1] via signal [SIGINT]
PM2        | 2024-03-18T13:39:18: PM2 log: App [server:0] starting in -fork mode-
PM2        | 2024-03-18T13:39:18: PM2 log: App [server:0] online
PM2        | 2024-03-18T13:39:19: PM2 log: App [server:0] exited with code [1] via signal [SIGINT]
PM2        | 2024-03-18T13:39:19: PM2 log: App [server:0] starting in -fork mode-
PM2        | 2024-03-18T13:39:19: PM2 log: App [server:0] online
ultimate-tester commented 7 months ago

Not sure if this is related to PM2. I see the PM2 report states NodeJS 20 and the ?? operator is available since NodeJS 14 so not sure what goes wrong here. This is mostly related to your code. Does it run fine by running it manually rather than through PM2?

gomeslucasf commented 4 months ago

In my case, the issue was undefined environment variables.

I created the ecosystem.config.js file as instructed in the documentation ((https://pm2.keymetrics.io/docs/usage/application-declaration/)) and configured the environment variables as required (https://pm2.keymetrics.io/docs/usage/environment/).

With this setup, my application is working. I am currently checking with the hosting team regarding the ports