Move "restart" to daemon/restart.go

This is part of an effort to break apart the deprecated server/ package

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
Solomon Hykes 2014-07-31 20:48:23 +00:00 коммит произвёл Tibor Vass
Родитель 4180b87514
Коммит bd54a73c42
4 изменённых файлов: 30 добавлений и 23 удалений

Просмотреть файл

@ -132,6 +132,9 @@ func (daemon *Daemon) Install(eng *engine.Engine) error {
if err := eng.Register("start", daemon.ContainerStart); err != nil {
return err
}
if err := eng.Register("restart", daemon.ContainerRestart); err != nil {
return err
}
return nil
}

27
daemon/restart.go Normal file
Просмотреть файл

@ -0,0 +1,27 @@
package daemon
import (
"github.com/docker/docker/engine"
)
func (daemon *Daemon) ContainerRestart(job *engine.Job) engine.Status {
if len(job.Args) != 1 {
return job.Errorf("Usage: %s CONTAINER\n", job.Name)
}
var (
name = job.Args[0]
t = 10
)
if job.EnvExists("t") {
t = job.GetenvInt("t")
}
if container := daemon.Get(name); container != nil {
if err := container.Restart(int(t)); err != nil {
return job.Errorf("Cannot restart container %s: %s\n", name, err)
}
job.Eng.Job("log", "restart", container.ID, daemon.Repositories().ImageName(container.Image)).Run()
} else {
return job.Errorf("No such container: %s\n", name)
}
return engine.StatusOK
}

Просмотреть файл

@ -261,28 +261,6 @@ func (srv *Server) ContainerCommit(job *engine.Job) engine.Status {
return engine.StatusOK
}
func (srv *Server) ContainerRestart(job *engine.Job) engine.Status {
if len(job.Args) != 1 {
return job.Errorf("Usage: %s CONTAINER\n", job.Name)
}
var (
name = job.Args[0]
t = 10
)
if job.EnvExists("t") {
t = job.GetenvInt("t")
}
if container := srv.daemon.Get(name); container != nil {
if err := container.Restart(int(t)); err != nil {
return job.Errorf("Cannot restart container %s: %s\n", name, err)
}
srv.LogEvent("restart", container.ID, srv.daemon.Repositories().ImageName(container.Image))
} else {
return job.Errorf("No such container: %s\n", name)
}
return engine.StatusOK
}
func (srv *Server) ContainerDestroy(job *engine.Job) engine.Status {
if len(job.Args) != 1 {
return job.Errorf("Not enough arguments. Usage: %s CONTAINER\n", job.Name)

Просмотреть файл

@ -86,7 +86,6 @@ func InitServer(job *engine.Job) engine.Status {
job.Eng.Hack_SetGlobalVar("httpapi.daemon", srv.daemon)
for name, handler := range map[string]engine.Handler{
"restart": srv.ContainerRestart,
"wait": srv.ContainerWait,
"tag": srv.ImageTag, // FIXME merge with "image_tag"
"resize": srv.ContainerResize,