Merge pull request #541 from abligh/support-unix-domain-control-socket

Support using a unix domain socket for the HTTP control interface.
This commit is contained in:
rade committed 2015-04-10 20:39:11 +01:00
commit 551c1d2925
1 file changed
+14 -3
+14 -3
View File
@@ -15,6 +15,7 @@ import (
"os"
"os/signal"
"runtime"
"strings"
"syscall"
)
@@ -60,7 +61,7 @@ func main() {
flag.IntVar(&connLimit, "connlimit", 30, "connection limit (0 for unlimited)")
flag.IntVar(&bufSz, "bufsz", 8, "capture buffer size in MB")
flag.IntVar(&port, "port", weave.Port, "router port")
flag.StringVar(&httpAddr, "httpaddr", fmt.Sprintf(":%d", weave.HTTPPort), "address to bind HTTP interface to (disabled if blank)")
flag.StringVar(&httpAddr, "httpaddr", fmt.Sprintf(":%d", weave.HTTPPort), "address to bind HTTP interface to (disabled if blank, , absolute path indicates unix domain socket)")
flag.Parse()
peers = flag.Args()
@@ -200,9 +201,19 @@ func handleHTTP(router *weave.Router, httpAddr string) {
http.Handle("/", muxRouter)
err := http.ListenAndServe(httpAddr, nil)
protocol := "tcp"
if strings.HasPrefix(httpAddr, "/") {
os.Remove(httpAddr); // in case it's there from last time
protocol = "unix"
}
l, err := net.Listen(protocol, httpAddr)
if err != nil {
log.Fatal("Unable to create http listener: ", err)
log.Fatal("Unable to create http listener socket: ", err)
}
err = http.Serve(l, nil)
if err != nil {
log.Fatal("Unable to create http server", err)
}
}