Move systemd.Manager initialization into a function in that module
This will permit us to extend the internals of systemd.Manager to include further information about the system, such as whether cgroupv1, cgroupv2 or both are in effect. Furthermore, it allows a future refactor of moving more of UseSystemd() code into the factory initialization function. Signed-off-by: Filipe Brandenburger <filbranden@gmail.com>
This commit is contained in:
parent
dae70e8efe
commit
46351eb3d1
|
@ -18,6 +18,10 @@ func UseSystemd() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewSystemdCgroupsManager() (func(config *configs.Cgroup, paths map[string]string) cgroups.Manager, error) {
|
||||||
|
return nil, fmt.Errorf("Systemd not supported")
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Manager) Apply(pid int) error {
|
func (m *Manager) Apply(pid int) error {
|
||||||
return fmt.Errorf("Systemd not supported")
|
return fmt.Errorf("Systemd not supported")
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,6 +163,18 @@ func UseSystemd() bool {
|
||||||
return hasStartTransientUnit
|
return hasStartTransientUnit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewSystemdCgroupsManager() (func(config *configs.Cgroup, paths map[string]string) cgroups.Manager, error) {
|
||||||
|
if !systemdUtil.IsRunningSystemd() {
|
||||||
|
return nil, fmt.Errorf("systemd not running on this host, can't use systemd as a cgroups.Manager")
|
||||||
|
}
|
||||||
|
return func(config *configs.Cgroup, paths map[string]string) cgroups.Manager {
|
||||||
|
return &Manager{
|
||||||
|
Cgroups: config,
|
||||||
|
Paths: paths,
|
||||||
|
}
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Manager) Apply(pid int) error {
|
func (m *Manager) Apply(pid int) error {
|
||||||
var (
|
var (
|
||||||
c = m.Cgroups
|
c = m.Cgroups
|
||||||
|
|
|
@ -51,12 +51,11 @@ func InitArgs(args ...string) func(*LinuxFactory) error {
|
||||||
// SystemdCgroups is an options func to configure a LinuxFactory to return
|
// SystemdCgroups is an options func to configure a LinuxFactory to return
|
||||||
// containers that use systemd to create and manage cgroups.
|
// containers that use systemd to create and manage cgroups.
|
||||||
func SystemdCgroups(l *LinuxFactory) error {
|
func SystemdCgroups(l *LinuxFactory) error {
|
||||||
l.NewCgroupsManager = func(config *configs.Cgroup, paths map[string]string) cgroups.Manager {
|
systemdCgroupsManager, err := systemd.NewSystemdCgroupsManager()
|
||||||
return &systemd.Manager{
|
if err != nil {
|
||||||
Cgroups: config,
|
return err
|
||||||
Paths: paths,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
l.NewCgroupsManager = systemdCgroupsManager
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue