Skip to content

Commit 0dea09b

Browse files
committed
*: use coreos/go-systemd/activation for socket activation
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
1 parent 8e8d01d commit 0dea09b

File tree

6 files changed

+163
-24
lines changed

6 files changed

+163
-24
lines changed

Godeps/Godeps.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Godeps/_workspace/src/github.com/coreos/go-systemd/activation/files.go

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Godeps/_workspace/src/github.com/coreos/go-systemd/activation/listeners.go

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Godeps/_workspace/src/github.com/coreos/go-systemd/activation/packetconns.go

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

start.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ import (
66
"fmt"
77
"os"
88
"runtime"
9-
"strconv"
109
"syscall"
1110

1211
"github.com/Sirupsen/logrus"
1312
"github.com/codegangsta/cli"
13+
"github.com/coreos/go-systemd/activation"
1414
"github.com/opencontainers/runc/libcontainer"
1515
"github.com/opencontainers/specs"
1616
)
1717

18-
const SD_LISTEN_FDS_START = 3
19-
2018
// default action is to start a container
2119
var startCommand = cli.Command{
2220
Name: "start",
@@ -59,17 +57,10 @@ var startCommand = cli.Command{
5957
setupSdNotify(spec, notifySocket)
6058
}
6159

62-
var (
63-
listenFds = os.Getenv("LISTEN_FDS")
64-
listenPid = os.Getenv("LISTEN_PID")
65-
)
66-
if listenFds != "" && listenPid == strconv.Itoa(os.Getpid()) {
67-
setupSocketActivation(spec, listenFds)
68-
}
69-
7060
if os.Geteuid() != 0 {
7161
logrus.Fatal("runc should be run as root")
7262
}
63+
7364
status, err := startContainer(context, spec)
7465
if err != nil {
7566
logrus.Fatalf("Container start failed: %v", err)
@@ -124,12 +115,10 @@ func startContainer(context *cli.Context, spec *specs.LinuxSpec) (int, error) {
124115
process := newProcess(spec.Process)
125116
// Support on-demand socket activation by passing file descriptors into the container init process.
126117
if os.Getenv("LISTEN_FDS") != "" {
127-
listenFdsInt, err := strconv.Atoi(os.Getenv("LISTEN_FDS"))
128-
if err != nil {
129-
return -1, err
130-
}
131-
for i := SD_LISTEN_FDS_START; i < (listenFdsInt + SD_LISTEN_FDS_START); i++ {
132-
process.ExtraFiles = append(process.ExtraFiles, os.NewFile(uintptr(i), ""))
118+
listenFds := activation.Files(false)
119+
if len(listenFds) > 0 {
120+
process.Env = append(process.Env, fmt.Sprintf("LISTEN_FDS=%d", len(listenFds)), "LISTEN_PID=1")
121+
process.ExtraFiles = append(process.ExtraFiles, listenFds...)
133122
}
134123
}
135124
tty, err := setupIO(process, rootuid, context.String("console"), spec.Process.Terminal, detach)

utils.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,6 @@ func setupSdNotify(spec *specs.LinuxSpec, notifySocket string) {
236236
spec.Process.Env = append(spec.Process.Env, fmt.Sprintf("NOTIFY_SOCKET=%s", notifySocket))
237237
}
238238

239-
// If systemd is supporting on-demand socket activation, this function will add support
240-
// for on-demand socket activation for the containerized service.
241-
func setupSocketActivation(spec *specs.LinuxSpec, listenFds string) {
242-
spec.Process.Env = append(spec.Process.Env, fmt.Sprintf("LISTEN_FDS=%s", listenFds), "LISTEN_PID=1")
243-
}
244-
245239
func destroy(container libcontainer.Container) {
246240
if err := container.Destroy(); err != nil {
247241
logrus.Error(err)

0 commit comments

Comments
 (0)