systemd: Export IsSystemdRunning() function
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
4a9e1747da
commit
33c6125da6
|
@ -14,7 +14,7 @@ type Manager struct {
|
||||||
Paths map[string]string
|
Paths map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func UseSystemd() bool {
|
func IsRunningSystemd() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ func newProp(name string, units interface{}) systemdDbus.Property {
|
||||||
// system. This functions similarly to systemd's `sd_booted(3)`: internally, it
|
// system. This functions similarly to systemd's `sd_booted(3)`: internally, it
|
||||||
// checks whether /run/systemd/system/ exists and is a directory.
|
// checks whether /run/systemd/system/ exists and is a directory.
|
||||||
// http://www.freedesktop.org/software/systemd/man/sd_booted.html
|
// http://www.freedesktop.org/software/systemd/man/sd_booted.html
|
||||||
func isRunningSystemd() bool {
|
func IsRunningSystemd() bool {
|
||||||
fi, err := os.Lstat("/run/systemd/system")
|
fi, err := os.Lstat("/run/systemd/system")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
@ -116,7 +116,7 @@ func UseSystemd() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSystemdCgroupsManager() (func(config *configs.Cgroup, paths map[string]string) cgroups.Manager, error) {
|
func NewSystemdCgroupsManager() (func(config *configs.Cgroup, paths map[string]string) cgroups.Manager, error) {
|
||||||
if !isRunningSystemd() {
|
if !IsRunningSystemd() {
|
||||||
return nil, fmt.Errorf("systemd not running on this host, can't use systemd as a cgroups.Manager")
|
return nil, fmt.Errorf("systemd not running on this host, can't use systemd as a cgroups.Manager")
|
||||||
}
|
}
|
||||||
if cgroups.IsCgroup2UnifiedMode() {
|
if cgroups.IsCgroup2UnifiedMode() {
|
||||||
|
|
|
@ -506,7 +506,7 @@ func TestFreeze(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSystemdFreeze(t *testing.T) {
|
func TestSystemdFreeze(t *testing.T) {
|
||||||
if !systemd.UseSystemd() {
|
if !systemd.IsRunningSystemd() {
|
||||||
t.Skip("Systemd is unsupported")
|
t.Skip("Systemd is unsupported")
|
||||||
}
|
}
|
||||||
testFreeze(t, true)
|
testFreeze(t, true)
|
||||||
|
@ -563,7 +563,7 @@ func TestCpuShares(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCpuSharesSystemd(t *testing.T) {
|
func TestCpuSharesSystemd(t *testing.T) {
|
||||||
if !systemd.UseSystemd() {
|
if !systemd.IsRunningSystemd() {
|
||||||
t.Skip("Systemd is unsupported")
|
t.Skip("Systemd is unsupported")
|
||||||
}
|
}
|
||||||
testCpuShares(t, true)
|
testCpuShares(t, true)
|
||||||
|
@ -598,7 +598,7 @@ func TestPids(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPidsSystemd(t *testing.T) {
|
func TestPidsSystemd(t *testing.T) {
|
||||||
if !systemd.UseSystemd() {
|
if !systemd.IsRunningSystemd() {
|
||||||
t.Skip("Systemd is unsupported")
|
t.Skip("Systemd is unsupported")
|
||||||
}
|
}
|
||||||
testPids(t, true)
|
testPids(t, true)
|
||||||
|
@ -684,7 +684,7 @@ func TestRunWithKernelMemory(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunWithKernelMemorySystemd(t *testing.T) {
|
func TestRunWithKernelMemorySystemd(t *testing.T) {
|
||||||
if !systemd.UseSystemd() {
|
if !systemd.IsRunningSystemd() {
|
||||||
t.Skip("Systemd is unsupported")
|
t.Skip("Systemd is unsupported")
|
||||||
}
|
}
|
||||||
testRunWithKernelMemory(t, true)
|
testRunWithKernelMemory(t, true)
|
||||||
|
|
|
@ -47,7 +47,7 @@ func loadFactory(context *cli.Context) (libcontainer.Factory, error) {
|
||||||
cgroupManager = libcontainer.RootlessCgroupfs
|
cgroupManager = libcontainer.RootlessCgroupfs
|
||||||
}
|
}
|
||||||
if context.GlobalBool("systemd-cgroup") {
|
if context.GlobalBool("systemd-cgroup") {
|
||||||
if systemd.UseSystemd() {
|
if systemd.IsRunningSystemd() {
|
||||||
cgroupManager = libcontainer.SystemdCgroups
|
cgroupManager = libcontainer.SystemdCgroups
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("systemd cgroup flag passed, but systemd support for managing cgroups is not available")
|
return nil, fmt.Errorf("systemd cgroup flag passed, but systemd support for managing cgroups is not available")
|
||||||
|
|
Loading…
Reference in New Issue