我需要能够使用pm2启动下面的应用程序,但不知道如何使用pm2启动它。
node --expose-gc bin/www arg1 arg2 arg3
我知道--node-args
,但我认为它仅适用于--expose-gc
。
我需要能够使用pm2启动下面的应用程序,但不知道如何使用pm2启动它。
node --expose-gc bin/www arg1 arg2 arg3
我知道--node-args
,但我认为它仅适用于--expose-gc
。
经过一番查找,我发现我要找的是 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专家的人来说,这将非常好。
另一种方法是创建应用程序声明的 JSON 文件,在文件中指定 args
键。请查看 PM2 网站上的 文档。
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
您可以在-x --
后添加任何自定义参数,
pm2 start app.js -x -- --prod
并将node参数设置为--node-args="--harmony"
pm2 start app.js --node-args="--harmony"
两者皆可
pm2 start app.js --node-args="--harmony" -x -- --prod
我需要在我的pm2 process.js中开启expose-gc,因此我必须执行以下操作:
{
"apps" : [
{
"name" : "app",
"script" : "bin/www",
"instances" : 2,
"exec_mode" : "cluster",
"watch" : false,
"node_args" : "--expose-gc",
"env" : {"NODE_ENV": "development"}
}
]
}