|
|
|
@ -24,8 +24,6 @@ import ( |
|
|
|
|
"strconv" |
|
|
|
|
"strings" |
|
|
|
|
"sync" |
|
|
|
|
|
|
|
|
|
"github.com/minio/minio/pkg/probe" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// This package is a fork https://github.com/facebookgo/grace
|
|
|
|
@ -71,8 +69,8 @@ type fileListener interface { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// getInheritedListeners - look for LISTEN_FDS in environment variables and populate listeners accordingly
|
|
|
|
|
func (n *minNet) getInheritedListeners() *probe.Error { |
|
|
|
|
var retErr *probe.Error |
|
|
|
|
func (n *minNet) getInheritedListeners() error { |
|
|
|
|
var retErr error |
|
|
|
|
n.inheritOnce.Do(func() { |
|
|
|
|
n.mutex.Lock() |
|
|
|
|
defer n.mutex.Unlock() |
|
|
|
@ -82,7 +80,7 @@ func (n *minNet) getInheritedListeners() *probe.Error { |
|
|
|
|
} |
|
|
|
|
count, err := strconv.Atoi(countStr) |
|
|
|
|
if err != nil { |
|
|
|
|
retErr = probe.NewError(fmt.Errorf("found invalid count value: %s=%s", envCountKey, countStr)) |
|
|
|
|
retErr = fmt.Errorf("found invalid count value: %s=%s", envCountKey, countStr) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -92,18 +90,18 @@ func (n *minNet) getInheritedListeners() *probe.Error { |
|
|
|
|
l, err := net.FileListener(file) |
|
|
|
|
if err != nil { |
|
|
|
|
file.Close() |
|
|
|
|
retErr = probe.NewError(err) |
|
|
|
|
retErr = err |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if err := file.Close(); err != nil { |
|
|
|
|
retErr = probe.NewError(err) |
|
|
|
|
retErr = err |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
n.inheritedListeners = append(n.inheritedListeners, l) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
if retErr != nil { |
|
|
|
|
return retErr.Trace() |
|
|
|
|
return retErr |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
@ -112,20 +110,20 @@ func (n *minNet) getInheritedListeners() *probe.Error { |
|
|
|
|
// a stream-oriented network: "tcp", "tcp4", "tcp6", "unix" or "unixpacket". It
|
|
|
|
|
// returns an inherited net.Listener for the matching network and address, or
|
|
|
|
|
// creates a new one using net.Listen()
|
|
|
|
|
func (n *minNet) Listen(nett, laddr string) (net.Listener, *probe.Error) { |
|
|
|
|
func (n *minNet) Listen(nett, laddr string) (net.Listener, error) { |
|
|
|
|
switch nett { |
|
|
|
|
default: |
|
|
|
|
return nil, probe.NewError(net.UnknownNetworkError(nett)) |
|
|
|
|
return nil, net.UnknownNetworkError(nett) |
|
|
|
|
case "tcp", "tcp4", "tcp6": |
|
|
|
|
addr, err := net.ResolveTCPAddr(nett, laddr) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, probe.NewError(err) |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
return n.ListenTCP(nett, addr) |
|
|
|
|
case "unix", "unixpacket": |
|
|
|
|
addr, err := net.ResolveUnixAddr(nett, laddr) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, probe.NewError(err) |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
return n.ListenUnix(nett, addr) |
|
|
|
|
} |
|
|
|
@ -134,9 +132,9 @@ func (n *minNet) Listen(nett, laddr string) (net.Listener, *probe.Error) { |
|
|
|
|
// ListenTCP announces on the local network address laddr. The network net must
|
|
|
|
|
// be: "tcp", "tcp4" or "tcp6". It returns an inherited net.Listener for the
|
|
|
|
|
// matching network and address, or creates a new one using net.ListenTCP.
|
|
|
|
|
func (n *minNet) ListenTCP(nett string, laddr *net.TCPAddr) (net.Listener, *probe.Error) { |
|
|
|
|
func (n *minNet) ListenTCP(nett string, laddr *net.TCPAddr) (net.Listener, error) { |
|
|
|
|
if err := n.getInheritedListeners(); err != nil { |
|
|
|
|
return nil, err.Trace() |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
n.mutex.Lock() |
|
|
|
@ -158,7 +156,7 @@ func (n *minNet) ListenTCP(nett string, laddr *net.TCPAddr) (net.Listener, *prob |
|
|
|
|
// make a fresh listener
|
|
|
|
|
l, err := net.ListenTCP(nett, laddr) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, probe.NewError(err) |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
n.activeListeners = append(n.activeListeners, rateLimitedListener(l, n.connLimit)) |
|
|
|
|
return l, nil |
|
|
|
@ -167,9 +165,9 @@ func (n *minNet) ListenTCP(nett string, laddr *net.TCPAddr) (net.Listener, *prob |
|
|
|
|
// ListenUnix announces on the local network address laddr. The network net
|
|
|
|
|
// must be a: "unix" or "unixpacket". It returns an inherited net.Listener for
|
|
|
|
|
// the matching network and address, or creates a new one using net.ListenUnix.
|
|
|
|
|
func (n *minNet) ListenUnix(nett string, laddr *net.UnixAddr) (net.Listener, *probe.Error) { |
|
|
|
|
func (n *minNet) ListenUnix(nett string, laddr *net.UnixAddr) (net.Listener, error) { |
|
|
|
|
if err := n.getInheritedListeners(); err != nil { |
|
|
|
|
return nil, err.Trace() |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
n.mutex.Lock() |
|
|
|
@ -191,7 +189,7 @@ func (n *minNet) ListenUnix(nett string, laddr *net.UnixAddr) (net.Listener, *pr |
|
|
|
|
// make a fresh listener
|
|
|
|
|
l, err := net.ListenUnix(nett, laddr) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, probe.NewError(err) |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
n.activeListeners = append(n.activeListeners, rateLimitedListener(l, n.connLimit)) |
|
|
|
|
return l, nil |
|
|
|
@ -232,7 +230,7 @@ func (n1 minAddr) IsEqual(n2 net.Addr) bool { |
|
|
|
|
// arguments as when it was originally started. This allows for a newly
|
|
|
|
|
// deployed binary to be started. It returns the pid of the newly started
|
|
|
|
|
// process when successful.
|
|
|
|
|
func (n *minNet) StartProcess() (int, *probe.Error) { |
|
|
|
|
func (n *minNet) StartProcess() (int, error) { |
|
|
|
|
listeners := n.getActiveListeners() |
|
|
|
|
// Extract the fds from the listeners.
|
|
|
|
|
files := make([]*os.File, len(listeners)) |
|
|
|
@ -240,7 +238,7 @@ func (n *minNet) StartProcess() (int, *probe.Error) { |
|
|
|
|
var err error |
|
|
|
|
files[i], err = l.(fileListener).File() |
|
|
|
|
if err != nil { |
|
|
|
|
return 0, probe.NewError(err) |
|
|
|
|
return 0, err |
|
|
|
|
} |
|
|
|
|
defer files[i].Close() |
|
|
|
|
} |
|
|
|
@ -249,7 +247,7 @@ func (n *minNet) StartProcess() (int, *probe.Error) { |
|
|
|
|
// the file it points to has been changed we will use the updated symlink.
|
|
|
|
|
argv0, err := exec.LookPath(os.Args[0]) |
|
|
|
|
if err != nil { |
|
|
|
|
return 0, probe.NewError(err) |
|
|
|
|
return 0, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Pass on the environment and replace the old count key with the new one.
|
|
|
|
@ -268,7 +266,7 @@ func (n *minNet) StartProcess() (int, *probe.Error) { |
|
|
|
|
Files: allFiles, |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
return 0, probe.NewError(err) |
|
|
|
|
return 0, err |
|
|
|
|
} |
|
|
|
|
return process.Pid, nil |
|
|
|
|
} |
|
|
|
|