Example #1
0
func (this *Cgroup) UnmarshalJSON(b []byte) error {
	type tmp Cgroup
	cg := tmp{}

	cgroup.Init()

	if err := json.Unmarshal(b, &cg); err != nil {
		return err
	}

	this.Name = cg.Name
	this.Cgroup = cgroup.NewCgroup(cg.Name)

	if err := this.SetControllers(cg.Controllers); err != nil {
		return err
	}

	if err := this.Cgroup.Create(); err != nil {
		return err
	}

	if err := this.SetParams(cg.Controllers); err != nil {
		return err
	}

	this.Controllers = cg.Controllers

	return nil
}
Example #2
0
// Working with cgroups
// 1. Init
// 2. Init Cgroup struct
// 3. Set controllers
// 4. Physically create cgroup
// 5. Set controllers values
func NewCgroup(name string) (*Cgroup, error) {
	this := &Cgroup{Name: name}

	cgroup.Init()

	this.Cgroup = cgroup.NewCgroup(name)

	return this, nil
}