-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible to use systemd activation for UDP sockets as well. #27
Conversation
Refactor the wrapping of sockets into a separate function. For every fd, try it as a packet socket first. If it errors out, try net.Listener.
Hi, I was wondering is there anything else needed for this to be merged? thanks |
@theraphim Thanks for the contribution. What do you think about adding an |
@philips well, you would usually want to retrieve all of your sockets at once. The order may also matter to you. I can create PacketConns method with semantics similar to Listeners, which may be good for simple daemons like tftp server, but for more complex cases where your service does both udp and tcp I haven't found a better approach than retrieving them and wrapping them all in one call. |
+1 |
@theraphim Your more complex app wouldn't want the TCP and UDP sockets separated though? |
@theraphim If your main concern is that you want to get the ordering then how about we return a slice of Listeners and a slice of ints that tells us the order? Or a slice of type ActivationListener that has the integer for ordering such as:
|
@philips not sure what do you mean. If I'm doing it through WrapSystemdSockets, I'm getting back both udp and tcp sockets, in one call, preserving the ordering. |
@theraphim The wrapped socket struct is sort of annoying because it is two completely different things and I have to check for nil on both. Iterating is cheap since this is only done on startup. |
@theraphim How about we have a type assertion switch that people should use? So the function prototype becomes:
|
I don't really like the 'TcpOrUdp' struct. The ordering proposed with the ActivationListener seems sane and simple. It would need to ActivationPacketConn as well? Using this is just, sort -> iterate -> start daemon |
@miekg So the total interface would become:
|
Yes, that would tie in nicely with #54. And drop the 's' on net.PacketConnS :)
|
I'll let @porjo chip in. If we hear nothing the next few days I will hammer
|
Can someone explain to me why anyone would care about socket ordering? Is it worth the extra level of indirection? |
Socket ordering might matter if I am having different levels of service on different items. that way, if you don't care about the order, just ls, _, err := it |
@theraphim That makes sense but isn't the sequence of the sockets within the slice itself sufficient ordering for this case? i.e. why do we need an additional |
No because the app might rxpect UDP and TCP sockets.
|
I'm still not seeing how the For the scenario where you have multiple services running from one process, the app would have internal config (taken from command line args for example) telling it which protocol/port it should use for which service. It should then be matching those up with what |
@porjo Sockets can be configured in a specific order. From the systemd docs: "Sockets configured in one unit are passed in the order of configuration, but no ordering between socket units is specified." http://www.freedesktop.org/software/systemd/man/systemd.socket.html |
IIRC systemd passes sockets down in order they're specified in a corresponding .socket file; therefore I can reasonably assign different service levels depending on the order they're coming in the environment. |
@philips @theraphim Yes, I know sockets are sent from Systemd in a particular order and I see now why this is useful. My question is why the packetConns, _ := activation.PacketConns(false)
listeners, _ := activation.Listeners(true)
// Start our tftp service on the first UDP port returned
tftpConn := packetConns[0]
// start our api on the second TCP port returned
apiListener := listeners[1]
// and so on... I've updated my branch and replaced |
@porjo This seems reasonable to me, no idea why I didn't think of it before the Order thing... let me know when you have a PR ready! :) |
On Tue, Aug 5, 2014 at 7:55 PM, Ian Bishop notifications@github.com wrote:
Reopened. |
Refactor the wrapping of sockets into a separate function. For every
fd, try it as a packet socket first. If it errors out, try net.Listener.