From 388d143d197d324e175e76f9eb4691defa33307f Mon Sep 17 00:00:00 2001 From: Alexandr Morozov Date: Tue, 19 Aug 2014 16:27:31 +0400 Subject: [PATCH] Remove dependency from docker/pkg/systemd Signed-off-by: Alexandr Morozov --- cgroups/systemd/apply_systemd.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cgroups/systemd/apply_systemd.go b/cgroups/systemd/apply_systemd.go index 7fcd99bce..252fb60e4 100644 --- a/cgroups/systemd/apply_systemd.go +++ b/cgroups/systemd/apply_systemd.go @@ -13,8 +13,7 @@ import ( "sync" "time" - systemd1 "github.com/coreos/go-systemd/dbus" - "github.com/docker/docker/pkg/systemd" + systemd "github.com/coreos/go-systemd/dbus" "github.com/docker/libcontainer/cgroups" "github.com/docker/libcontainer/cgroups/fs" "github.com/godbus/dbus" @@ -30,7 +29,7 @@ type subsystem interface { var ( connLock sync.Mutex - theConn *systemd1.Conn + theConn *systemd.Conn hasStartTransientUnit bool subsystems = map[string]subsystem{ "devices": &fs.DevicesGroup{}, @@ -45,7 +44,8 @@ var ( ) func UseSystemd() bool { - if !systemd.SdBooted() { + s, err := os.Stat("/run/systemd/system") + if err != nil || !s.IsDir() { return false } @@ -54,7 +54,7 @@ func UseSystemd() bool { if theConn == nil { var err error - theConn, err = systemd1.New() + theConn, err = systemd.New() if err != nil { return false } @@ -88,7 +88,7 @@ func Apply(c *cgroups.Cgroup, pid int) (cgroups.ActiveCgroup, error) { var ( unitName = getUnitName(c) slice = "system.slice" - properties []systemd1.Property + properties []systemd.Property res = &systemdCgroup{} ) @@ -99,27 +99,27 @@ func Apply(c *cgroups.Cgroup, pid int) (cgroups.ActiveCgroup, error) { } properties = append(properties, - systemd1.Property{"Slice", dbus.MakeVariant(slice)}, - systemd1.Property{"Description", dbus.MakeVariant("docker container " + c.Name)}, - systemd1.Property{"PIDs", dbus.MakeVariant([]uint32{uint32(pid)})}, + systemd.Property{"Slice", dbus.MakeVariant(slice)}, + systemd.Property{"Description", dbus.MakeVariant("docker container " + c.Name)}, + systemd.Property{"PIDs", dbus.MakeVariant([]uint32{uint32(pid)})}, ) // Always enable accounting, this gets us the same behaviour as the fs implementation, // plus the kernel has some problems with joining the memory cgroup at a later time. properties = append(properties, - systemd1.Property{"MemoryAccounting", dbus.MakeVariant(true)}, - systemd1.Property{"CPUAccounting", dbus.MakeVariant(true)}, - systemd1.Property{"BlockIOAccounting", dbus.MakeVariant(true)}) + systemd.Property{"MemoryAccounting", dbus.MakeVariant(true)}, + systemd.Property{"CPUAccounting", dbus.MakeVariant(true)}, + systemd.Property{"BlockIOAccounting", dbus.MakeVariant(true)}) if c.Memory != 0 { properties = append(properties, - systemd1.Property{"MemoryLimit", dbus.MakeVariant(uint64(c.Memory))}) + systemd.Property{"MemoryLimit", dbus.MakeVariant(uint64(c.Memory))}) } // TODO: MemoryReservation and MemorySwap not available in systemd if c.CpuShares != 0 { properties = append(properties, - systemd1.Property{"CPUShares", dbus.MakeVariant(uint64(c.CpuShares))}) + systemd.Property{"CPUShares", dbus.MakeVariant(uint64(c.CpuShares))}) } if _, err := theConn.StartTransientUnit(unitName, "replace", properties...); err != nil {