【问题标题】:How to pass node v8 args and script args to pm2?如何将节点 v8 参数和脚本参数传递给 pm2?
【发布时间】:2015-02-25 18:20:06
【问题描述】:

我需要能够用 pm2 启动下面的应用程序,但不知道如何用 pm2 启动它。

node --expose-gc bin/www arg1 arg2 arg3

我知道--node-args,但我认为仅适用于--expose-gc。

【问题讨论】:

    标签: node.js production pm2


    【解决方案1】:

    经过一番挖掘,我发现我正在寻找的是 linux 上的双破折号。

    普通代码,

    node --expose-gc bin/www arg1 arg2 arg3
    

    使用 pm2 的相同代码

    pm2 start bin/www --node-args="--expose-gc" -- arg1 arg2 arg3
    

    所有 v8 参数都必须放在 --node-args 中,所有要从 process.argv 抓取的脚本参数都必须放在双破折号之后。

    我希望将来他们实现一些链接 --script-args="arg1 arg2 arg3"。对于那些不是 linux 专家的人来说会非常好。

    【讨论】:

      【解决方案2】:

      另一种方法是创建应用程序声明 json 文件,在其中指定 args 键。在 PM2 网站上查看documentation

      pm2.json 文件示例:

      {
        "apps" : [{
          "name"        : "appname",
          "script"      : "app.js",
          "args"        : ["-s", "123"],
          "node_args"   : "--harmony",
          "merge_logs"  : true,
          "cwd"         : "/this/is/a/path/to/start/script",
          "env": {
              "NODE_ENV": "production"
          }
        }]
      }
      

      并按如下方式运行:

      $ pm2 start pm2.json
      

      【讨论】:

        【解决方案3】:

        您可以在-x -- 之后添加任何自定义参数,

        pm2 start app.js -x -- --prod

        节点参数为--node-args="--harmony"

        pm2 start app.js --node-args="--harmony"

        两者

        pm2 start app.js --node-args="--harmony" -x -- --prod

        【讨论】:

        【解决方案4】:

        我不得不在我的 pm2 process.js 中暴露-gc,所以我做了以下事情:

        {
          "apps" : [
            {
              "name"        : "app",
              "script"      : "bin/www",
              "instances"   : 2,
              "exec_mode"   : "cluster",
              "watch"       : false,
              "node_args"   : "--expose-gc",
              "env"         : {"NODE_ENV": "development"}
            }
          ]
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-12-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-10-03
          • 2021-08-18
          • 2018-01-15
          • 2020-07-18
          相关资源
          最近更新 更多