Skip to content

Commit d223e2a

Browse files
Ignore error when starting transient unit that already exists
Signed-off-by: Derek Carr <decarr@redhat.com>
1 parent 88b4c48 commit d223e2a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

libcontainer/cgroups/systemd/apply_systemd.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (m *Manager) Apply(pid int) error {
282282
}
283283
}
284284

285-
if _, err := theConn.StartTransientUnit(unitName, "replace", properties, nil); err != nil {
285+
if _, err := theConn.StartTransientUnit(unitName, "replace", properties, nil); err != nil && !isUnitExists(err) {
286286
return err
287287
}
288288

@@ -546,3 +546,13 @@ func setKernelMemory(c *configs.Cgroup) error {
546546
}
547547
return fs.EnableKernelMemoryAccounting(path)
548548
}
549+
550+
// isUnitExists returns true if the error is that a systemd unit already exists.
551+
func isUnitExists(err error) bool {
552+
if err != nil {
553+
if dbusError, ok := err.(dbus.Error); ok {
554+
return strings.Contains(dbusError.Name, "org.freedesktop.systemd1.UnitExists")
555+
}
556+
}
557+
return false
558+
}

0 commit comments

Comments
 (0)