Example #1
0
func (d *driver) Unpause(c *execdriver.Command) error {
	active := d.activeContainers[c.ID]
	if active == nil {
		return fmt.Errorf("active container for %s does not exist", c.ID)
	}
	active.container.Cgroups.Freezer = "THAWED"
	if systemd.UseSystemd() {
		return systemd.Freeze(active.container.Cgroups, active.container.Cgroups.Freezer)
	}
	return fs.Freeze(active.container.Cgroups, active.container.Cgroups.Freezer)
}
Example #2
0
// SetupCgroups applies the cgroup restrictions to the process running in the container based
// on the container's configuration
func SetupCgroups(container *libcontainer.Config, nspid int) (cgroups.ActiveCgroup, error) {
	if container.Cgroups != nil {
		c := container.Cgroups

		if systemd.UseSystemd() {
			return systemd.Apply(c, nspid)
		}

		return fs.Apply(c, nspid)
	}

	return nil, nil
}
Example #3
0
func toggle(state cgroups.FreezerState) error {
	container, err := loadConfig()
	if err != nil {
		return err
	}

	if systemd.UseSystemd() {
		err = systemd.Freeze(container.Cgroups, state)
	} else {
		err = fs.Freeze(container.Cgroups, state)
	}

	return err
}
Example #4
0
func (d *driver) GetPidsForContainer(id string) ([]int, error) {
	d.Lock()
	active := d.activeContainers[id]
	d.Unlock()

	if active == nil {
		return nil, fmt.Errorf("active container for %s does not exist", id)
	}
	c := active.container.Cgroups

	if systemd.UseSystemd() {
		return systemd.GetPids(c)
	}
	return fs.GetPids(c)
}
Example #5
0
func destroyAction(context *cli.Context) {
	config, err := getConfig(context)
	if err != nil {
		log.Fatal(err)
	}

	killAll(config)
	// Systemd will clean up cgroup state for empty container.
	if !systemd.UseSystemd() {
		err := fs.Cleanup(config)
		if err != nil {
			log.Fatal(err)
		}
	}
}
Example #6
0
func setFreezerState(context *cli.Context, state cgroups.FreezerState) {
	config, err := getConfig(context)
	if err != nil {
		log.Fatal(err)
	}

	if systemd.UseSystemd() {
		err = systemd.Freeze(config, state)
	} else {
		err = fs.Freeze(config, state)
	}
	if err != nil {
		log.Fatal(err)
	}
}
Example #7
0
// TODO(vmarmol): Complete Stats() in final libcontainer API and move users to that.
// DEPRECATED: The below portions are only to be used during the transition to the official API.
// Returns all available stats for the given container.
func GetStats(container *Config, state *State) (*ContainerStats, error) {
	var (
		err   error
		stats = &ContainerStats{}
	)

	if systemd.UseSystemd() {
		stats.CgroupStats, err = systemd.GetStats(container.Cgroups)
	} else {
		stats.CgroupStats, err = fs.GetStats(container.Cgroups)
	}

	if err != nil {
		return stats, err
	}

	stats.NetworkStats, err = network.GetStats(&state.NetworkState)

	return stats, err
}
Example #8
0
func createAction(context *cli.Context) {
	config, err := getConfigFromFile(context)
	if err != nil {
		log.Fatal(err)
	}
	pid := context.Int("pid")
	if pid <= 0 {
		log.Fatal(fmt.Errorf("Invalid pid : %d", pid))
	}
	if systemd.UseSystemd() {
		_, err := systemd.Apply(config, pid)
		if err != nil {
			log.Fatal(err)
		}
	} else {
		_, err := fs.Apply(config, pid)
		if err != nil {
			log.Fatal(err)
		}
	}
}