isMaster 相当于 pm2 [英] isMaster equivalent for pm2
本文介绍了isMaster 相当于 pm2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我过去曾使用 cluster
来运行多个实例,但想开始使用 pm2
.但是,我有一个只能在启动的实例之一上运行的进程.
I've used cluster
in the past for running multiple instances, but would like to start using pm2
. However, I have a process that should only run on one of the instances launched.
在使用pm2
时,有没有办法确定或识别最初启动的实例,相当于isMaster
?
Is there a way to determine or identify the initially launched instance, an equivalent to isMaster
when using 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
这篇关于isMaster 相当于 pm2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文