mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
panic on missing runc root
This commit is contained in:
parent
e71b6cacce
commit
b5361c2a28
@ -20,6 +20,31 @@ type RuncOpts struct {
|
|||||||
systemdCgroups bool // use systemd cgroups
|
systemdCgroups bool // use systemd cgroups
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewRuncOpts() (RuncOpts, error) {
|
||||||
|
var opts RuncOpts
|
||||||
|
// read runc root path
|
||||||
|
root := os.Getenv("RUNC_ROOT")
|
||||||
|
if root == "" {
|
||||||
|
root = "/run/runc"
|
||||||
|
}
|
||||||
|
abs, err := filepath.Abs(root)
|
||||||
|
if err != nil {
|
||||||
|
return opts, err
|
||||||
|
}
|
||||||
|
opts.root = abs
|
||||||
|
|
||||||
|
// ensure runc root path is readable
|
||||||
|
_, err = ioutil.ReadDir(opts.root)
|
||||||
|
if err != nil {
|
||||||
|
return opts, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if os.Getenv("RUNC_SYSTEMD_CGROUP") == "1" {
|
||||||
|
opts.systemdCgroups = true
|
||||||
|
}
|
||||||
|
return opts, nil
|
||||||
|
}
|
||||||
|
|
||||||
type Runc struct {
|
type Runc struct {
|
||||||
opts RuncOpts
|
opts RuncOpts
|
||||||
factory libcontainer.Factory
|
factory libcontainer.Factory
|
||||||
@ -30,7 +55,7 @@ type Runc struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRunc() Connector {
|
func NewRunc() Connector {
|
||||||
opts, err := readRuncOpts()
|
opts, err := NewRuncOpts()
|
||||||
runcFailOnErr(err)
|
runcFailOnErr(err)
|
||||||
|
|
||||||
factory, err := getFactory(opts)
|
factory, err := getFactory(opts)
|
||||||
@ -198,25 +223,6 @@ func (cm *Runc) All() (containers container.Containers) {
|
|||||||
return containers
|
return containers
|
||||||
}
|
}
|
||||||
|
|
||||||
func readRuncOpts() (RuncOpts, error) {
|
|
||||||
var opts RuncOpts
|
|
||||||
// read runc root path
|
|
||||||
root := os.Getenv("RUNC_ROOT")
|
|
||||||
if root == "" {
|
|
||||||
root = "/run/runc"
|
|
||||||
}
|
|
||||||
abs, err := filepath.Abs(root)
|
|
||||||
if err != nil {
|
|
||||||
return opts, err
|
|
||||||
}
|
|
||||||
opts.root = abs
|
|
||||||
|
|
||||||
if os.Getenv("RUNC_SYSTEMD_CGROUP") == "1" {
|
|
||||||
opts.systemdCgroups = true
|
|
||||||
}
|
|
||||||
return opts, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getFactory(opts RuncOpts) (libcontainer.Factory, error) {
|
func getFactory(opts RuncOpts) (libcontainer.Factory, error) {
|
||||||
cgroupManager := libcontainer.Cgroupfs
|
cgroupManager := libcontainer.Cgroupfs
|
||||||
if opts.systemdCgroups {
|
if opts.systemdCgroups {
|
||||||
|
Loading…
Reference in New Issue
Block a user