[英]How to restart a node app via pm2 and apply new config file?
I have a node app running on Ubuntu 18.04.我有一个在 Ubuntu 18.04 上运行的节点应用程序。 It was started using PM2 like so
pm2 start./bin/web_server.js
它是使用 PM2 开始的,就像
pm2 start./bin/web_server.js
Under some circumstances the process runs out of memory throwing this error:在某些情况下,进程用完 memory 并抛出此错误:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0xa18150 node::Abort() [node /path/to/app/bin/web_server.js]
2: 0xa1855c node::OnFatalError(char const*, char const*) [node /path/to/app/bin/web_server.js]
...
...
So I want to increase the heap size, which seems to be pretty straitforward for a node process.所以我想增加堆大小,这对于节点进程来说似乎非常严格。 All one has to do is run it with the proper parameter set.
所要做的就是使用正确的参数集运行它。 eg
node --max-old-space-size=2048./bin/web_server.js
例如
node --max-old-space-size=2048./bin/web_server.js
Since I am already running my process using PM2, I want to pass the max-old-space-size
parameter to node using PM2's ecosystem.config.js
file.由于我已经使用 PM2 运行我的进程,我想使用 PM2 的
ecosystem.config.js
.config.js 文件将max-old-space-size
参数传递给节点。 So I proceeded to add this config file into the APP's root directory.所以我继续将此配置文件添加到APP的根目录中。 The contents are here:
内容在这里:
module.exports = {
apps : [{
name: 'IntuListAPI',
script: './bin/web_server.js',
//watch: true,
//watch_delay: 1000,
max_memory_restart: '20G',
node_args: [
"--max-old-space-size=6144"
]
}]
};
Now when I run pm2 restart web_server
I expect PM2 to pick up the new config and restart my process with it.现在,当我运行
pm2 restart web_server
时,我希望 PM2 能够获取新配置并使用它重新启动我的进程。 But it does not seem to work and I can't figure out why.但它似乎不起作用,我不知道为什么。 Since it was originally started without
ecosystem.config.js
, is it now ignoring it?既然一开始就没有
ecosystem.config.js
,现在是忽略了吗?
To be sure, the process restarts just fine, it just doesn't restart with the new heap size.可以肯定的是,该进程重新启动就好了,它只是不会以新的堆大小重新启动。
After some further research, I learned that in order to accomplish this I had to delete my APP from pm2 and then restart it using the ecosystem.config.js
file.经过一些进一步的研究,我了解到为了实现这一点,我必须从 pm2 中删除我的 APP,然后使用
ecosystem.config.js
.config.js 文件重新启动它。 These two commands is all I needed:我只需要这两个命令:
pm2 delete web_server
pm2 start ecosystem.config.js
The last command will start up ./bin/web_server.js
and apply all the specified parameters.最后一个命令将启动
./bin/web_server.js
并应用所有指定的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.