-
-
Save isaacs/2563474 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var cluster = require('cluster') | |
| if (cluster.isMaster) { | |
| // spawn worker bees | |
| cluster.fork() | |
| cluster.fork() | |
| cluster.fork() | |
| cluster.fork() | |
| } else { | |
| // worker bees only need root to listen, and then downgrade | |
| var http = require('http') | |
| http.createServer(function (req, res) { | |
| res.writeHead(200) | |
| res.end('ok') | |
| }).listen(80, function () { | |
| if (process.getuid() === 0) process.setuid(-2) | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be nice to be able to do the downgrade once - in the master - rather than each time a child launches.
This is also probably a bit more secure, since children never have elevated privs at all.