Extract function to listen on Unix socket
This commit is contained in:
1 parent
c2a869491f
commit
78f2d82984
3 files changed
+22
-11
No files matched your search
@@ -0,0 +1,18 @@
|
|||||||
|
package net
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ListenUnixSocket(pathname string) (net.Listener, error) {
|
||||||
|
if err := os.Remove(pathname); err != nil && !os.IsNotExist(err) {
|
||||||
|
return nil, fmt.Errorf("Error removing existing unix socket: %s", err)
|
||||||
|
}
|
||||||
|
listener, err := net.Listen("unix", pathname)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("ListenUnixSocket failed: %s", err)
|
||||||
|
}
|
||||||
|
return listener, nil
|
||||||
|
}
|
||||||
+2
-7
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/docker/libnetwork/ipamapi"
|
"github.com/docker/libnetwork/ipamapi"
|
||||||
. "github.com/weaveworks/weave/common"
|
. "github.com/weaveworks/weave/common"
|
||||||
"github.com/weaveworks/weave/common/docker"
|
"github.com/weaveworks/weave/common/docker"
|
||||||
|
weavenet "github.com/weaveworks/weave/net"
|
||||||
ipamplugin "github.com/weaveworks/weave/plugin/ipam"
|
ipamplugin "github.com/weaveworks/weave/plugin/ipam"
|
||||||
netplugin "github.com/weaveworks/weave/plugin/net"
|
netplugin "github.com/weaveworks/weave/plugin/net"
|
||||||
"github.com/weaveworks/weave/plugin/skel"
|
"github.com/weaveworks/weave/plugin/skel"
|
||||||
@@ -101,13 +102,7 @@ func listenAndServe(dockerClient *docker.Client, address string, noMulticastRout
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var listener net.Listener
|
listener, err := weavenet.ListenUnixSocket(address)
|
||||||
|
|
||||||
// remove sockets from last invocation
|
|
||||||
if err := os.Remove(address); err != nil && !os.IsNotExist(err) {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
listener, err = net.Listen("unix", address)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-4
@@ -19,6 +19,7 @@ import (
|
|||||||
docker "github.com/fsouza/go-dockerclient"
|
docker "github.com/fsouza/go-dockerclient"
|
||||||
. "github.com/weaveworks/weave/common"
|
. "github.com/weaveworks/weave/common"
|
||||||
weavedocker "github.com/weaveworks/weave/common/docker"
|
weavedocker "github.com/weaveworks/weave/common/docker"
|
||||||
|
weavenet "github.com/weaveworks/weave/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -296,10 +297,7 @@ func (proxy *Proxy) Serve(listeners []net.Listener) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (proxy *Proxy) ListenAndServeStatus(socket string) {
|
func (proxy *Proxy) ListenAndServeStatus(socket string) {
|
||||||
if err := os.Remove(socket); err != nil && !os.IsNotExist(err) {
|
listener, err := weavenet.ListenUnixSocket(socket)
|
||||||
Log.Fatalf("Error removing existing status socket: %s", err)
|
|
||||||
}
|
|
||||||
listener, err := net.Listen("unix", socket)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log.Fatalf("ListenAndServeStatus failed: %s", err)
|
Log.Fatalf("ListenAndServeStatus failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user