Blob Blame History Raw
diff -up docker-0be3e217c42ecf554bf5117bec9c832bd3f3b6fd/runc-66aedde759f33c190954815fb765eedc1d782dd9/libcontainer/cgroups/systemd/apply_systemd.go.orig docker-0be3e217c42ecf554bf5117bec9c832bd3f3b6fd/runc-66aedde759f33c190954815fb765eedc1d782dd9/libcontainer/cgroups/systemd/apply_systemd.go
--- docker-7d71120b1f31f8bb4da733b5f1e5960b434696de/runc-283e28b7d8a5ba31dd51213ce9126f3e0d529cfb/libcontainer/cgroups/systemd/apply_systemd.go.orig	2021-02-12 11:34:42.913036670 +0100
+++ docker-7d71120b1f31f8bb4da733b5f1e5960b434696de/runc-283e28b7d8a5ba31dd51213ce9126f3e0d529cfb/libcontainer/cgroups/systemd/apply_systemd.go	2021-02-12 11:37:14.165696606 +0100
@@ -7,6 +7,7 @@ import (
 	"fmt"
 	"io/ioutil"
 	"os"
+	"os/exec"
 	"path/filepath"
 	"strings"
 	"sync"
@@ -130,6 +131,10 @@ func (m *Manager) Apply(pid int) error {
 		properties = append(properties, newProp("PIDs", []uint32{uint32(pid)}))
 	}
 
+	if systemdHasCollectMode() {
+		properties = append(properties, newProp("CollectMode", "inactive-or-failed"))
+	}
+
 	// This is only supported on systemd versions 218 and above.
 	properties = append(properties, newProp("Delegate", true))
 
@@ -473,3 +478,13 @@ func isUnitExists(err error) bool {
 	}
 	return false
 }
+
+func systemdHasCollectMode() bool {
+	// This will show whether the currently running systemd supports CollectMode
+	_, err := exec.Command("systemctl", "show", "-p", "CollectMode", "systemd").Output()
+	if err != nil {
+		logrus.Debugf("Failed to check systemd CollectMode: %v", err)
+		return false
+	}
+	return true
+}