1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Move "stop" to daemon/stop.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:40:15 +00:00 committed by Tibor Vass
parent 80f3272ee9
commit 03c07617cc
4 changed files with 33 additions and 26 deletions

View file

@ -126,6 +126,9 @@ func (daemon *Daemon) Install(eng *engine.Engine) error {
if err := eng.Register("create", daemon.ContainerCreate); err != nil {
return err
}
if err := eng.Register("stop", daemon.ContainerStop); err != nil {
return err
}
return nil
}

30
daemon/stop.go Normal file
View file

@ -0,0 +1,30 @@
package daemon
import (
"github.com/docker/docker/engine"
)
func (daemon *Daemon) ContainerStop(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 !container.State.IsRunning() {
return job.Errorf("Container already stopped")
}
if err := container.Stop(int(t)); err != nil {
return job.Errorf("Cannot stop container %s: %s\n", name, err)
}
job.Eng.Job("log", "stop", container.ID, daemon.Repositories().ImageName(container.Image)).Run()
} else {
return job.Errorf("No such container: %s\n", name)
}
return engine.StatusOK
}

View file

@ -467,31 +467,6 @@ func (srv *Server) ContainerStart(job *engine.Job) engine.Status {
return engine.StatusOK
}
func (srv *Server) ContainerStop(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 !container.State.IsRunning() {
return job.Errorf("Container already stopped")
}
if err := container.Stop(int(t)); err != nil {
return job.Errorf("Cannot stop container %s: %s\n", name, err)
}
srv.LogEvent("stop", container.ID, srv.daemon.Repositories().ImageName(container.Image))
} else {
return job.Errorf("No such container: %s\n", name)
}
return engine.StatusOK
}
func (srv *Server) ContainerWait(job *engine.Job) engine.Status {
if len(job.Args) != 1 {
return job.Errorf("Usage: %s", job.Name)

View file

@ -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{
"stop": srv.ContainerStop,
"restart": srv.ContainerRestart,
"start": srv.ContainerStart,
"wait": srv.ContainerWait,