带有 systemd 和传递节点参数的 pm2

Nit*_*tai 1 ubuntu-server node.js systemd pm2 ubuntu-16.04

我想用 pm2 和环境变量(如--nouse-idle-notificationor )启动节点--max-old-space-size=2048

但是,无论我做什么,它都不会传递节点变量。我用 mp2 和一个配置文件启动我的应用程序。配置文件如下所示:

{
  "apps" : [{
    "env": {
      "NODE_PATH": "/usr/bin/node",
      "interpreter_args": "--max-old-space-size=2048 --nouse-idle-notification"
    },
    "env_development": {
      "NODE_ENV": "development"
    },
    "env_production" : {
       "NODE_ENV": "production",
       "APP_TYPE": "web"
    },
    "exec_mode"   : "fork",
    "name"        : "MyApp",
    "script"      : "/opt/myapp/app.js",
    "watch"       : false,
    "out_file"    : "/var/log/app.log",
    "error_file"  : "/var/log/app.log",
    "combine_logs": true,
    "node_args": "--max-old-space-size=2048 --nouse-idle-notification",
    "args": "--max-old-space-size=2048 --nouse-idle-notification"
  }]
}
Run Code Online (Sandbox Code Playgroud)

(如您所见,我尝试以多种方式传入节点变量)

然后我用以下命令启动应用程序:

pm2 restart pathtojsonfile --env production
Run Code Online (Sandbox Code Playgroud)

一切都正常启动,我在我的代码中看到了像“MY_APP”这样的变量。但是,现在当我用“top”查看过程时,我只看到:

node /opt/myapp/app.js
Run Code Online (Sandbox Code Playgroud)

当我永久或手动启动应用程序时,我可以看到如下过程:

node --max-old-space-size=2048 --nouse-idle-notification /opt/myapp/app.js
Run Code Online (Sandbox Code Playgroud)

pm2 只是没有显示这些节点参数还是它们真的没有传入?(pm2 启动的进程使用较少的内存)

Roh*_*rte 9

下面是使用 node-args 启动 pm2 的 extact 命令

pm2 start app.js --node-args="--max-old-space-size=4096"
Run Code Online (Sandbox Code Playgroud)


Uni*_*ech 5

通过使用 "node_args": "--max-old-space-size=2048 --nouse-idle-notification" 你做了正确的事情,并且这些参数被考虑在内。

PM2 重命名进程并删除进程标题中指定的节点参数。