mirror of
https://github.com/clearlinux/docker.git
synced 2026-10-03 23:38:24 +00:00
Add ability to pause/unpause containers via cgroups freeze
This patch adds pause/unpause to the command line, api, and drivers for use on containers. This is implemented using the cgroups/freeze utility in libcontainer and lxc freeze/unfreeze. Co-Authored-By: Eric Windisch <ewindisch@docker.com> Co-Authored-By: Chris Alfonso <calfonso@redhat.com> Docker-DCO-1.1-Signed-off-by: Ian Main <imain@redhat.com> (github: imain)
This commit is contained in:
@@ -27,6 +27,7 @@ var actions = map[string]Action{
|
||||
"cgroups.memory_reservation": memoryReservation, // set the memory reservation
|
||||
"cgroups.memory_swap": memorySwap, // set the memory swap limit
|
||||
"cgroups.cpuset.cpus": cpusetCpus, // set the cpus used
|
||||
"cgroups.freezer": freezer, // set the frozen/thaw state
|
||||
|
||||
"systemd.slice": systemdSlice, // set parent Slice used for systemd unit
|
||||
|
||||
@@ -35,6 +36,16 @@ var actions = map[string]Action{
|
||||
"fs.readonly": readonlyFs, // make the rootfs of the container read only
|
||||
}
|
||||
|
||||
func freezer(container *libcontainer.Container, context interface{}, value string) error {
|
||||
if container.Cgroups == nil {
|
||||
return fmt.Errorf("cannot set cgroups when they are disabled")
|
||||
}
|
||||
|
||||
container.Cgroups.Freezer = value
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func cpusetCpus(container *libcontainer.Container, context interface{}, value string) error {
|
||||
if container.Cgroups == nil {
|
||||
return fmt.Errorf("cannot set cgroups when they are disabled")
|
||||
|
||||
@@ -145,6 +145,32 @@ func (d *driver) Kill(p *execdriver.Command, sig int) error {
|
||||
return syscall.Kill(p.Process.Pid, syscall.Signal(sig))
|
||||
}
|
||||
|
||||
func (d *driver) Pause(c *execdriver.Command) error {
|
||||
active := d.activeContainers[c.ID]
|
||||
active.container.Cgroups.Freezer = "FROZEN"
|
||||
pid := c.Process.Pid
|
||||
|
||||
if systemd.UseSystemd() {
|
||||
_, err := systemd.Apply(active.container.Cgroups, pid)
|
||||
return err
|
||||
}
|
||||
_, err := fs.Apply(active.container.Cgroups, pid)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *driver) Unpause(c *execdriver.Command) error {
|
||||
active := d.activeContainers[c.ID]
|
||||
active.container.Cgroups.Freezer = "THAWED"
|
||||
pid := c.Process.Pid
|
||||
|
||||
if systemd.UseSystemd() {
|
||||
_, err := systemd.Apply(active.container.Cgroups, pid)
|
||||
return err
|
||||
}
|
||||
_, err := fs.Apply(active.container.Cgroups, pid)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *driver) Terminate(p *execdriver.Command) error {
|
||||
// lets check the start time for the process
|
||||
started, err := d.readStartTime(p)
|
||||
|
||||
Reference in New Issue
Block a user