github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/daemon/unpause.go (about)

     1  package daemon
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/docker/docker/container"
     8  	"github.com/sirupsen/logrus"
     9  )
    10  
    11  // ContainerUnpause unpauses a container
    12  func (daemon *Daemon) ContainerUnpause(name string) error {
    13  	container, err := daemon.GetContainer(name)
    14  	if err != nil {
    15  		return err
    16  	}
    17  
    18  	if err := daemon.containerUnpause(container); err != nil {
    19  		return err
    20  	}
    21  
    22  	return nil
    23  }
    24  
    25  // containerUnpause resumes the container execution after the container is paused.
    26  func (daemon *Daemon) containerUnpause(container *container.Container) error {
    27  	container.Lock()
    28  	defer container.Unlock()
    29  
    30  	// We cannot unpause the container which is not paused
    31  	if !container.Paused {
    32  		return fmt.Errorf("Container %s is not paused", container.ID)
    33  	}
    34  
    35  	if err := daemon.containerd.Resume(context.Background(), container.ID); err != nil {
    36  		return fmt.Errorf("Cannot unpause container %s: %s", container.ID, err)
    37  	}
    38  
    39  	container.Paused = false
    40  	daemon.setStateCounter(container)
    41  	daemon.updateHealthMonitor(container)
    42  	daemon.LogContainerEvent(container, "unpause")
    43  
    44  	if err := container.CheckpointTo(daemon.containersReplica); err != nil {
    45  		logrus.WithError(err).Warnf("could not save container to disk")
    46  	}
    47  
    48  	return nil
    49  }