github.com/mheon/docker@v0.11.2-0.20150922122814-44f47903a831/daemon/restart.go (about)

     1  package daemon
     2  
     3  import "fmt"
     4  
     5  // ContainerRestart stops and starts a container. It attempts to
     6  // gracefully stop the container within the given timeout, forcefully
     7  // stopping it if the timeout is exceeded. If given a negative
     8  // timeout, ContainerRestart will wait forever until a graceful
     9  // stop. Returns an error if the container cannot be found, or if
    10  // there is an underlying error at any stage of the restart.
    11  func (daemon *Daemon) ContainerRestart(name string, seconds int) error {
    12  	container, err := daemon.Get(name)
    13  	if err != nil {
    14  		return err
    15  	}
    16  	if err := container.Restart(seconds); err != nil {
    17  		return fmt.Errorf("Cannot restart container %s: %s\n", name, err)
    18  	}
    19  	return nil
    20  }