listen/bind in deterministic order for consistent error messages, and warn if quickstart cannot find public ip's

without public ip's, the generated mox config will try to listen on 0.0.0.0 and
::, but because there is already a listener for 127.0.0.1:80 (and possibly
others), a bind for 0.0.0.0:80 will fail. explicit public ip's are needed.

the public http listener is useful for ACME validation over http.

for issue #52
This commit is contained in:
Mechiel Lukkien
2023-08-10 10:29:06 +02:00
parent 01bcd98a42
commit 038b478d16
4 changed files with 40 additions and 6 deletions

View File

@ -18,6 +18,8 @@ import (
_ "net/http/pprof"
"golang.org/x/exp/maps"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
@ -362,7 +364,13 @@ func Listen() {
}
}
for name, l := range mox.Conf.Static.Listeners {
// Initialize listeners in deterministic order for the same potential error
// messages.
names := maps.Keys(mox.Conf.Static.Listeners)
sort.Strings(names)
for _, name := range names {
l := mox.Conf.Static.Listeners[name]
portServe := map[int]*serve{}
var ensureServe func(https bool, port int, kind string) *serve
@ -546,7 +554,10 @@ func Listen() {
ensureManagerHosts[m] = hosts
}
for port, srv := range portServe {
ports := maps.Keys(portServe)
sort.Ints(ports)
for _, port := range ports {
srv := portServe[port]
sort.Slice(srv.PathHandlers, func(i, j int) bool {
a := srv.PathHandlers[i].Path
b := srv.PathHandlers[j].Path