繁体   English   中英

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

[英]pm2 with systemd and passing node argument

我想使用--nouse-idle-notification和环境变量(如--nouse-idle-notification--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"
  }]
}

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

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

pm2 restart pathtojsonfile --env production

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

node /opt/myapp/app.js

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

node --max-old-space-size=2048 --nouse-idle-notification /opt/myapp/app.js

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

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

pm2 start app.js --node-args="--max-old-space-size=4096"

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM