forked from containers/common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
systemd.go
58 lines (47 loc) · 992 Bytes
/
systemd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// +build systemd
package config
import (
"io/ioutil"
"strings"
"sync"
"github.com/containers/common/pkg/cgroupv2"
"github.com/containers/storage/pkg/unshare"
)
var (
systemdOnce sync.Once
usesSystemd bool
)
func defaultCgroupManager() string {
if !useSystemd() {
return CgroupfsCgroupsManager
}
enabled, err := cgroupv2.Enabled()
if err == nil && !enabled && unshare.IsRootless() {
return CgroupfsCgroupsManager
}
return SystemdCgroupsManager
}
func defaultEventsLogger() string {
if useSystemd() {
return "journald"
}
return "file"
}
func defaultLogDriver() string {
// If we decide to change the default for logdriver, it should be done here.
if useSystemd() {
return DefaultLogDriver
}
return DefaultLogDriver
}
func useSystemd() bool {
systemdOnce.Do(func() {
dat, err := ioutil.ReadFile("/proc/1/comm")
if err == nil {
val := strings.TrimSuffix(string(dat), "\n")
usesSystemd = (val == "systemd")
}
return
})
return usesSystemd
}