Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions sdk/unix_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
"github.com/docker/go-connections/sockets"
)

const (
pluginSockDir = "/run/docker/plugins"
)
const pluginSockDir = "/run/docker/plugins"

func newUnixListener(pluginName string, gid int) (net.Listener, string, error) {
path, err := fullSocketAddress(pluginName)
Expand Down
10 changes: 10 additions & 0 deletions sdk/unix_listener_nosystemd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// +build linux freebsd
// +build nosystemd

package sdk

import "net"

func setupSocketActivation() (net.Listener, error) {
return nil, nil
}
45 changes: 45 additions & 0 deletions sdk/unix_listener_systemd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// +build linux freebsd
// +build !nosystemd

package sdk

import (
"fmt"
"net"
"os"

"github.com/coreos/go-systemd/activation"
)

// isRunningSystemd checks whether the host was booted with systemd as its init
// system. This functions similarly to systemd's `sd_booted(3)`: internally, it
// checks whether /run/systemd/system/ exists and is a directory.
// http://www.freedesktop.org/software/systemd/man/sd_booted.html
//
// Copied from github.com/coreos/go-systemd/util.IsRunningSystemd
Copy link
Contributor Author

@tiborvass tiborvass Nov 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually if we do this, we probably don't need to have build tags, but it'd be less dependencies with nosystemd tag.

func isRunningSystemd() bool {
fi, err := os.Lstat("/run/systemd/system")
if err != nil {
return false
}
return fi.IsDir()
}

func setupSocketActivation() (net.Listener, error) {
if !isRunningSystemd() {
return nil, nil
}
listenFds := activation.Files(false)
if len(listenFds) > 1 {
return nil, fmt.Errorf("expected only one socket from systemd, got %d", len(listenFds))
}
var listener net.Listener
if len(listenFds) == 1 {
l, err := net.FileListener(listenFds[0])
if err != nil {
return nil, err
}
listener = l
}
return listener, nil
}