[英]isMaster equivalent for pm2
I've used cluster
in the past for running multiple instances, but would like to start using pm2
. 我过去使用
cluster
来运行多个实例,但是想开始使用pm2
。 However, I have a process that should only run on one of the instances launched. 但是,我有一个过程只能在启动的实例之一上运行。
Is there a way to determine or identify the initially launched instance, an equivalent to isMaster
when using pm2
? 有没有一种方法来确定或识别最初启动的实例,一个相当于
isMaster
使用时pm2
?
For those ones who search it, I've found this solution. 对于那些搜索它的人,我已经找到了解决方案。
if (process.env && process.env.pm_id) {
//running in pm2
if (process.env.pm_id % os.cpus().length !== 0) {
return;
}else{
collectSysInfo();
}
}
https://github.com/Unitech/pm2/issues/2035#issuecomment-199815595 https://github.com/Unitech/pm2/issues/2035#issuecomment-199815595
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.