naught
naught copied to clipboard
Server listening on existing socket / file descriptor
I have a server which listens on an existing socket:
http.createServer(app).listen({fd: 11});
This works fine if e.g. node server.js
is called directly by the process that sets up that socket.
It also works fine with the cluster module, because although the socket is only available to the master process, all listen()
invocations of the workers get passed to the master. So I merely have to have the master tell the workers what fd to listen on; I do that by passing them an environment variable when I fork them.
I'm unclear how to use naught
with this kind of situation, since the socket would only be available to naught
itself, and would not be available to my script which naught
would launch.
If I understand correctly, naught would need to pass the fd to the master when it spawns it in daemon.js:
master = spawn(process.execPath, nodeArgs.concat([path.join(__dirname, "master.js"), workerCount, script]).concat(argv), {
env: process.env,
stdio: [process.stdin, stdoutValue, stderrValue, 'ipc'],
cwd: process.cwd(),
});
That stdio array would get an additional value in it. For my case it would be something like:
var stdio = [process.stdin, stdoutValue, stderrValue, 'ipc'];
stdio[11] = 11;
master = spawn(process.execPath, nodeArgs.concat([path.join(__dirname, "master.js"), workerCount, script]).concat(argv), {
env: process.env,
stdio: stdio,
cwd: process.cwd(),
});
Perhaps there could be an additional argument that could be given to naught start
to tell it which additional fd(s) to share with the master.
Hi @ryandesign, did you ever figure this out? I'm trying to use naught under systemd socket activation (which uses fd3
and up) and having the same issue.
@jgrigg, I did implement this last year in a fork, for which I have now submitted a pull request.