Browse code

Remove pkg/systemd

Signed-off-by: Antonio Murdaca <runcom@linux.com>

Antonio Murdaca authored on 2015/08/06 21:35:00
Showing 3 changed files
... ...
@@ -10,8 +10,10 @@ import (
10 10
 
11 11
 	"github.com/docker/docker/daemon"
12 12
 	"github.com/docker/docker/pkg/sockets"
13
-	"github.com/docker/docker/pkg/systemd"
14 13
 	"github.com/docker/libnetwork/portallocator"
14
+
15
+	systemdActivation "github.com/coreos/go-systemd/activation"
16
+	systemdDaemon "github.com/coreos/go-systemd/daemon"
15 17
 )
16 18
 
17 19
 // newServer sets up the required serverClosers and does protocol specific checking.
... ...
@@ -22,7 +24,7 @@ func (s *Server) newServer(proto, addr string) ([]serverCloser, error) {
22 22
 	)
23 23
 	switch proto {
24 24
 	case "fd":
25
-		ls, err = systemd.ListenFD(addr)
25
+		ls, err = listenFD(addr)
26 26
 		if err != nil {
27 27
 			return nil, err
28 28
 		}
... ...
@@ -65,7 +67,7 @@ func (s *Server) AcceptConnections(d *daemon.Daemon) {
65 65
 	// Tell the init daemon we are accepting requests
66 66
 	s.daemon = d
67 67
 	s.registerSubRouter()
68
-	go systemd.SdNotify("READY=1")
68
+	go systemdDaemon.SdNotify("READY=1")
69 69
 	// close the lock so the listeners start accepting connections
70 70
 	select {
71 71
 	case <-s.start:
... ...
@@ -110,3 +112,34 @@ func getContainersByNameDownlevel(w http.ResponseWriter, s *Server, namevar stri
110 110
 	}
111 111
 	return writeJSON(w, http.StatusOK, containerJSONRaw)
112 112
 }
113
+
114
+// listenFD returns the specified socket activated files as a slice of
115
+// net.Listeners or all of the activated files if "*" is given.
116
+func listenFD(addr string) ([]net.Listener, error) {
117
+	// socket activation
118
+	listeners, err := systemdActivation.Listeners(false)
119
+	if err != nil {
120
+		return nil, err
121
+	}
122
+
123
+	if listeners == nil || len(listeners) == 0 {
124
+		return nil, fmt.Errorf("No sockets found")
125
+	}
126
+
127
+	// default to all fds just like unix:// and tcp://
128
+	if addr == "" {
129
+		addr = "*"
130
+	}
131
+
132
+	fdNum, _ := strconv.Atoi(addr)
133
+	fdOffset := fdNum - 3
134
+	if (addr != "*") && (len(listeners) < int(fdOffset)+1) {
135
+		return nil, fmt.Errorf("Too few socket activated files passed in")
136
+	}
137
+
138
+	if addr == "*" {
139
+		return listeners, nil
140
+	}
141
+
142
+	return []net.Listener{listeners[fdOffset]}, nil
143
+}
113 144
deleted file mode 100644
... ...
@@ -1,40 +0,0 @@
1
-package systemd
2
-
3
-import (
4
-	"errors"
5
-	"net"
6
-	"strconv"
7
-
8
-	"github.com/coreos/go-systemd/activation"
9
-)
10
-
11
-// ListenFD returns the specified socket activated files as a slice of
12
-// net.Listeners or all of the activated files if "*" is given.
13
-func ListenFD(addr string) ([]net.Listener, error) {
14
-	// socket activation
15
-	listeners, err := activation.Listeners(false)
16
-	if err != nil {
17
-		return nil, err
18
-	}
19
-
20
-	if listeners == nil || len(listeners) == 0 {
21
-		return nil, errors.New("No sockets found")
22
-	}
23
-
24
-	// default to all fds just like unix:// and tcp://
25
-	if addr == "" {
26
-		addr = "*"
27
-	}
28
-
29
-	fdNum, _ := strconv.Atoi(addr)
30
-	fdOffset := fdNum - 3
31
-	if (addr != "*") && (len(listeners) < int(fdOffset)+1) {
32
-		return nil, errors.New("Too few socket activated files passed in")
33
-	}
34
-
35
-	if addr == "*" {
36
-		return listeners, nil
37
-	}
38
-
39
-	return []net.Listener{listeners[fdOffset]}, nil
40
-}
41 1
deleted file mode 100644
... ...
@@ -1,34 +0,0 @@
1
-package systemd
2
-
3
-import (
4
-	"errors"
5
-	"net"
6
-	"os"
7
-)
8
-
9
-// ErrSdNotifyNoSocket is an error returned if no socket was specified.
10
-var ErrSdNotifyNoSocket = errors.New("No socket")
11
-
12
-// SdNotify sends a message to the init daemon. It is common to ignore the return value.
13
-func SdNotify(state string) error {
14
-	socketAddr := &net.UnixAddr{
15
-		Name: os.Getenv("NOTIFY_SOCKET"),
16
-		Net:  "unixgram",
17
-	}
18
-
19
-	if socketAddr.Name == "" {
20
-		return ErrSdNotifyNoSocket
21
-	}
22
-
23
-	conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr)
24
-	if err != nil {
25
-		return err
26
-	}
27
-
28
-	_, err = conn.Write([]byte(state))
29
-	if err != nil {
30
-		return err
31
-	}
32
-
33
-	return nil
34
-}