-
Notifications
You must be signed in to change notification settings - Fork 145
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
Support running on demand via systemd #151
Conversation
7aa41a3
to
b8058fe
Compare
cmd/rest-server/main.go
Outdated
panic(err) | ||
} | ||
|
||
switch len(listeners) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps make the systemd socket activation explicit with a --systemd
switch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you think that's needed? We can discover (from the environment) if we're run via systemd socket activation...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case you will end up ignoring the address configuration and using systemd instead, which could surprise the user. Adding a --systemd
flag also makes clear that some magic is happening here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, rest-server does log that it is in systemd mode, so I guess this is fine,
b8058fe
to
7f3ce33
Compare
cmd/rest-server/listener_windows.go
Outdated
// findListener creates a listener. | ||
func findListener(inetd bool, addr string) (listener net.Listener, err error) { | ||
if inetd { | ||
log.Print("inetd mode activated") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this even work on windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Via cygwin maybe? Or WSL? It compiled, so I left it there...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
inetd mode is off: #126 (comment) |
6921484
to
0f90ebf
Compare
0f90ebf
to
f90205e
Compare
// | ||
// systemd-socket-activate -l 8080 ./rest-server | ||
log.Printf("systemd socket activation mode") | ||
return listeners[0], nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure who should do the check, but if the environmental flags don't match the passed in file descriptors, listerners[0]
can be nil here and result in a panic later. Not a very nice to debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking that listeners[0]
is valid is probably a good idea before returning it. The expected behavior of findListener
is that it either returns a listening socket or an error. Returning nil
is thus wrong. Would you be willing to open a PR to check that listeners[0] != nil
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've opened coreos/go-systemd#405 for now, let's see if they are willing to fix the condition on their end.
What is the purpose of this change? What does it change?
This change allows
rest-server
to be run on demand by systemd (socket activation). The rationale for supporting both is as follows:rest-server
does not have to have the privileges to listen on a port.Was the change discussed in an issue or in the forum before?
Closes #126
Supersedes #127
Checklist
changelog/unreleased/
that describes the changes for our users (template here)gofmt
on the code in all commits