From 27bfd1e2d1d49d5170831b08b24cdafa6d6736fd Mon Sep 17 00:00:00 2001 From: Shishir Mahajan Date: Wed, 15 Jul 2015 10:50:22 -0400 Subject: [PATCH] systemd integration with container runtime for supporting sd_notify protocol Signed-off-by: Shishir Mahajan --- run.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/run.go b/run.go index ff581a607..b09c1fbff 100644 --- a/run.go +++ b/run.go @@ -67,6 +67,12 @@ func execContainer(context *cli.Context, spec *specs.LinuxSpec) (int, error) { // default action is to execute a container func runAction(context *cli.Context) { spec, err := loadSpec(context.Args().First()) + + notifySocket := os.Getenv("NOTIFY_SOCKET") + if notifySocket != "" { + setupSdNotify(spec, notifySocket) + } + if err != nil { fatal(err) } @@ -82,6 +88,13 @@ func runAction(context *cli.Context) { os.Exit(status) } +// If systemd is supporting sd_notify protocol, this function will add support +// for sd_notify protocol from within the container. +func setupSdNotify(spec *specs.LinuxSpec, notifySocket string) { + spec.Mounts = append(spec.Mounts, specs.Mount{Type: "bind", Source: notifySocket, Destination: notifySocket, Options: "bind"}) + spec.Process.Env = append(spec.Process.Env, fmt.Sprintf("NOTIFY_SOCKET=%s", notifySocket)) +} + func destroy(container libcontainer.Container) { status, err := container.Status() if err != nil {