Closed chewi closed 8 years ago
That's not a bad idea :)
Also, AFAIK, systemd's file descriptors always start from 3 so the user should be able to set it itself.
https://github.com/julien-f/simple-front-http-server/blob/master/sample.config.json#L15-L22
I agree it would be nice to handle this automatically but how does the library knows which config is associated with each FD if there are multiple ones?
The config is an array so I guess you'd need to put them in the same order as they are in the unit file. From man systemd.socket
:
Sockets configured in one unit are passed in the order of configuration, but no ordering between socket units is specified.
The config is not an array, the user as to call listen()
for each different “listen method.”
And I don't like relying on an implicit order, I think it would be best to add a specific method for systemd's sockets which would be provided a socket index:
server.listen({
systemdSocket: 0 // LISTEND_FDS + 0
})
Ah sorry, it's an array in xo-server and I thought it passed that in as-is but it iterates over it. Your suggestion sounds good.
I had hoped to work around this in the short term by just passing fd: 3
directly but I can't get it to work at all. I always get Web server could not listen on http://<fd:3>
and then it crashes. If I listen on TCP so it doesn't crash, I can see that the inode number for fd 3 under /proc matches the inode number shown by the ss
command. Oh well.
Hmmm, that's weird, I'm going to implement it very quickly to allow you to try it.
I just adjusted xo-server so that I could see the real error message. It's listen ENOTSOCK
.
Figured it out! It's because I was starting it with npm start
, if I do node bin/xo-server
, it works. I still get a Cannot read property 'address' of null
warning but it works anyway.
Ok, good for you :+1:
Released in v0.8.0.
(Will be available in the next version of Xen Orchestra).
Awesome, thanks very much.
I just hope it'll work ^^
This library supports passing a file descriptor but it would be really handy if it could check
LISTEN_FDS
andLISTEN_PID
environment variables to support systemd's socket activation. Applications using the library could do this but it would be more useful if the library could do it for you. Maybe accept alisten_fds
option or do this whensocket
istrue
instead of a string?This would sidestep #5 as systemd would be responsible for setting the socket permissions.