Log when listening (#350)

* Log when starting letsencrypt endpoint + clearer errors

Running `gotosocial server` with the default configuration will try to
bind to :80 and listen for letsencrypt challenges, which will fail if
running as non-root (w/o capabilities), or if eg. nginx hogs the port.

When that happens, this should make it more obvious what's wrong.

* Log what address/port we're listening on

Always nice not to have to guess. Also feels more consistent than just
doing it for the letsencrypt endpoint.
This commit is contained in:
embr 2021-12-20 10:34:57 +01:00 committed by GitHub
parent 80ec714117
commit 86e8e7fd21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -79,13 +79,15 @@ func (r *router) Start() {
// serve the http handler on the selected letsencrypt port, for receiving letsencrypt requests and solving their devious riddles // serve the http handler on the selected letsencrypt port, for receiving letsencrypt requests and solving their devious riddles
go func() { go func() {
listen := fmt.Sprintf("%s:%d", bindAddress, lePort) listen := fmt.Sprintf("%s:%d", bindAddress, lePort)
logrus.Infof("letsencrypt listening on %s", listen)
if err := http.ListenAndServe(listen, r.certManager.HTTPHandler(http.HandlerFunc(httpsRedirect))); err != nil && err != http.ErrServerClosed { if err := http.ListenAndServe(listen, r.certManager.HTTPHandler(http.HandlerFunc(httpsRedirect))); err != nil && err != http.ErrServerClosed {
logrus.Fatalf("listen: %s", err) logrus.Fatalf("letsencrypt: listen: %s", err)
} }
}() }()
// and serve the actual TLS handler // and serve the actual TLS handler
go func() { go func() {
logrus.Infof("listening on %s", r.srv.Addr)
if err := r.srv.ListenAndServeTLS("", ""); err != nil && err != http.ErrServerClosed { if err := r.srv.ListenAndServeTLS("", ""); err != nil && err != http.ErrServerClosed {
logrus.Fatalf("listen: %s", err) logrus.Fatalf("listen: %s", err)
} }
@ -93,6 +95,7 @@ func (r *router) Start() {
} else { } else {
// no tls required // no tls required
go func() { go func() {
logrus.Infof("listening on %s", r.srv.Addr)
if err := r.srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { if err := r.srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
logrus.Fatalf("listen: %s", err) logrus.Fatalf("listen: %s", err)
} }