Skip to content

Commit

Permalink
lxc: get rid of custom container detection code
Browse files Browse the repository at this point in the history
The mechanism for detecting whether or not the task is in a container here
(checking if we're in the / cgroup) is very broken, and will not work with
cgroup namespaces (to land in kernel 4.5, but will be backported to
xenial's 4.4 kernel).

Instead, we should use the running-in-container script, as provided by the
init-system-helpers package, which encapsulates all the logic required for
various init systems. (n.b. that this adds a dependency; I'm not sure how
juju handles this.)

Also, I've mode the code to container/ instead of in lxc/lxcutils in
anticipation of the lxd container type which will also need to use this
function.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
  • Loading branch information
Tycho Andersen committed Feb 4, 2016
1 parent b59d585 commit 24fef1a
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 177 deletions.
7 changes: 2 additions & 5 deletions cmd/jujud/agent/machine.go
Expand Up @@ -53,7 +53,6 @@ import (
"github.com/juju/juju/container"
"github.com/juju/juju/container/kvm"
"github.com/juju/juju/container/lxc"
"github.com/juju/juju/container/lxc/lxcutils"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/config"
"github.com/juju/juju/environs/simplestreams"
Expand Down Expand Up @@ -1943,10 +1942,8 @@ func (a *MachineAgent) uninstallAgent(agentConfig agent.Config) error {

errors = append(errors, a.removeJujudSymlinks()...)

insideLXC, err := lxcutils.RunningInsideLXC()
if err != nil {
errors = append(errors, err)
} else if insideLXC {
insideLXC := container.RunningInContainer()
if insideLXC {
// We're running inside LXC, so loop devices may leak. Detach
// any loop devices that are backed by files on this machine.
//
Expand Down
7 changes: 1 addition & 6 deletions container/lxc/lxc.go
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/juju/juju/cloudconfig/containerinit"
"github.com/juju/juju/cloudconfig/instancecfg"
"github.com/juju/juju/container"
"github.com/juju/juju/container/lxc/lxcutils"
"github.com/juju/juju/instance"
"github.com/juju/juju/storage/looputil"
)
Expand All @@ -44,7 +43,6 @@ var (
LxcRestartDir = "/etc/lxc/auto"
LxcObjectFactory = golxc.Factory()
runtimeGOOS = runtime.GOOS
runningInsideLXC = lxcutils.RunningInsideLXC
writeWgetTmpFile = ioutil.WriteFile
)

Expand Down Expand Up @@ -91,10 +89,7 @@ func IsLXCSupported() (bool, error) {
return false, nil
}
// We do not support running nested LXC containers.
insideLXC, err := runningInsideLXC()
if err != nil {
return false, errors.Trace(err)
}
insideLXC := container.RunningInContainer()
return !insideLXC, nil
}

Expand Down
8 changes: 0 additions & 8 deletions container/lxc/lxcutils/export_test.go

This file was deleted.

98 changes: 0 additions & 98 deletions container/lxc/lxcutils/lxcutils_test.go

This file was deleted.

12 changes: 0 additions & 12 deletions container/lxc/lxcutils/utils.go

This file was deleted.

38 changes: 0 additions & 38 deletions container/lxc/lxcutils/utils_linux.go

This file was deleted.

10 changes: 0 additions & 10 deletions container/lxc/lxcutils/utils_notlinux.go

This file was deleted.

14 changes: 14 additions & 0 deletions container/utils.go
@@ -0,0 +1,14 @@
package container

import (
"os/exec"
)

func RunningInContainer() bool {
/* running-in-container is in init-scripts-helpers, and is smart enough
* to ask both systemd and upstart whether or not they know if the task
* is running in a container.
*/
cmd := exec.Command("running-in-container")
return cmd.Run() == nil
}

0 comments on commit 24fef1a

Please sign in to comment.