-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update checkpoint/restore support in the daemon.
Docker-DCO-1.1-Signed-off-by: Ross Boucher <[email protected]> (github: boucher)
- Loading branch information
Showing
9 changed files
with
171 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,56 @@ | ||
package daemon | ||
|
||
import ( | ||
"github.com/docker/docker/engine" | ||
"fmt" | ||
|
||
"github.com/docker/libcontainer" | ||
) | ||
|
||
// Checkpoint a running container. | ||
func (daemon *Daemon) ContainerCheckpoint(job *engine.Job) engine.Status { | ||
if len(job.Args) != 1 { | ||
return job.Errorf("Usage: %s CONTAINER\n", job.Name) | ||
} | ||
|
||
name := job.Args[0] | ||
container, err := daemon.Get(name) | ||
if err != nil { | ||
return job.Error(err) | ||
} | ||
if !container.IsRunning() { | ||
return job.Errorf("Container %s not running", name) | ||
} | ||
|
||
if err := container.Checkpoint(); err != nil { | ||
return job.Errorf("Cannot checkpoint container %s: %s", name, err) | ||
} | ||
|
||
container.LogEvent("checkpoint") | ||
return engine.StatusOK | ||
func (daemon *Daemon) ContainerCheckpoint(name string, opts *libcontainer.CriuOpts) error { | ||
container, err := daemon.Get(name) | ||
if err != nil { | ||
return err | ||
} | ||
if !container.IsRunning() { | ||
return fmt.Errorf("Container %s not running", name) | ||
} | ||
if err := container.Checkpoint(opts); err != nil { | ||
return fmt.Errorf("Cannot checkpoint container %s: %s", name, err) | ||
} | ||
|
||
container.LogEvent("checkpoint") | ||
return nil | ||
} | ||
|
||
// Restore a checkpointed container. | ||
func (daemon *Daemon) ContainerRestore(job *engine.Job) engine.Status { | ||
if len(job.Args) != 1 { | ||
return job.Errorf("Usage: %s CONTAINER\n", job.Name) | ||
} | ||
|
||
name := job.Args[0] | ||
container, err := daemon.Get(name) | ||
if err != nil { | ||
return job.Error(err) | ||
} | ||
if container.IsRunning() { | ||
return job.Errorf("Container %s already running", name) | ||
} | ||
if !container.State.IsCheckpointed() { | ||
return job.Errorf("Container %s is not checkpointed", name) | ||
} | ||
|
||
if err := container.Restore(); err != nil { | ||
container.LogEvent("die") | ||
return job.Errorf("Cannot restore container %s: %s", name, err) | ||
} | ||
|
||
container.LogEvent("restore") | ||
return engine.StatusOK | ||
func (daemon *Daemon) ContainerRestore(name string, opts *libcontainer.CriuOpts, forceRestore bool) error { | ||
container, err := daemon.Get(name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !forceRestore { | ||
// TODO: It's possible we only want to bypass the checkpointed check, | ||
// I'm not sure how this will work if the container is already running | ||
if container.IsRunning() { | ||
return fmt.Errorf("Container %s already running", name) | ||
} | ||
|
||
if !container.IsCheckpointed() { | ||
return fmt.Errorf("Container %s is not checkpointed", name) | ||
} | ||
} else { | ||
if !container.HasBeenCheckpointed() && opts.ImagesDirectory == "" { | ||
return fmt.Errorf("You must specify an image directory to restore from %s", name) | ||
} | ||
} | ||
|
||
if err = container.Restore(opts, forceRestore); err != nil { | ||
container.LogEvent("die") | ||
return fmt.Errorf("Cannot restore container %s: %s", name, err) | ||
} | ||
|
||
container.LogEvent("restore") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.