Skip to content

Commit

Permalink
Ignore error when starting transient unit that already exists
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Carr <decarr@redhat.com>
  • Loading branch information
derekwaynecarr committed Oct 19, 2016
1 parent 88b4c48 commit d223e2a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion libcontainer/cgroups/systemd/apply_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (m *Manager) Apply(pid int) error {
}
}

if _, err := theConn.StartTransientUnit(unitName, "replace", properties, nil); err != nil {
if _, err := theConn.StartTransientUnit(unitName, "replace", properties, nil); err != nil && !isUnitExists(err) {
return err
}

Expand Down Expand Up @@ -546,3 +546,13 @@ func setKernelMemory(c *configs.Cgroup) error {
}
return fs.EnableKernelMemoryAccounting(path)
}

// isUnitExists returns true if the error is that a systemd unit already exists.
func isUnitExists(err error) bool {
if err != nil {
if dbusError, ok := err.(dbus.Error); ok {
return strings.Contains(dbusError.Name, "org.freedesktop.systemd1.UnitExists")
}
}
return false
}

0 comments on commit d223e2a

Please sign in to comment.