[英]Daemonizing node.js with child processes using cluster, setuid/setgid?
当守护一个分叉子进程的nodejs应用程序时,cluster.fork()中是否有一个选项可用于设置子进程的user:group? 对于主进程,我将用户和组设置为非root用户:
kue.app.listen(kueport, function() {
process.setgid("uocoder");
process.setuid("uocoder");
});
分叉子进程:
// FORK over all available cores
var clusterWorkerSize = require('os').cpus().length; // Get number of cores
console.log("Forking over all " + clusterWorkerSize + " cores");
for (var i = 0; i < clusterWorkerSize; i++) {
cluster.fork();
}
当使用init.d脚本作为守护程序运行时,子进程将以root用户身份运行,而主进程则使用我在代码中设置的uid和gid。
$ ps aux | grep uocoder
uocoder 1484 20.5 0.6 42348 23632 ? Sl 07:59 0:00 /usr/bin/nodejs /home/uocoder/uocoder/app.js
root 1487 21.5 0.5 40040 20812 ? Sl 07:59 0:00 /usr/bin/nodejs /home/uocoder/uocoder/app.js
root 1489 21.0 0.5 40040 20808 ? Sl 07:59 0:00 /usr/bin/nodejs /home/uocoder/uocoder/app.js
我还没有找到一种方法来在集群文档中设置子进程的uid和gid,也许我忽略了某些东西?
创建github问题,由pull 7882修复:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.