mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
commit
aaa1c48d24
5 changed files with 32 additions and 20 deletions
11
api.go
11
api.go
|
@ -678,17 +678,12 @@ func postContainersStop(srv *Server, version float64, w http.ResponseWriter, r *
|
||||||
if err := parseForm(r); err != nil {
|
if err := parseForm(r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
t, err := strconv.Atoi(r.Form.Get("t"))
|
|
||||||
if err != nil || t < 0 {
|
|
||||||
t = 10
|
|
||||||
}
|
|
||||||
|
|
||||||
if vars == nil {
|
if vars == nil {
|
||||||
return fmt.Errorf("Missing parameter")
|
return fmt.Errorf("Missing parameter")
|
||||||
}
|
}
|
||||||
name := vars["name"]
|
job := srv.Eng.Job("stop", vars["name"])
|
||||||
|
job.Setenv("t", r.Form.Get("t"))
|
||||||
if err := srv.ContainerStop(name, t); err != nil {
|
if err := job.Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
|
|
@ -190,4 +190,3 @@ func (o *Output) AddEnv() (dst *Env, err error) {
|
||||||
}()
|
}()
|
||||||
return dst, nil
|
return dst, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,8 +129,9 @@ func TestCreateRmVolumes(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = srv.ContainerStop(id, 1)
|
job = eng.Job("stop", id)
|
||||||
if err != nil {
|
job.SetenvInt("t", 1)
|
||||||
|
if err := job.Run(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +189,9 @@ func TestCreateStartRestartStopStartKillRm(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := srv.ContainerStop(id, 15); err != nil {
|
job = eng.Job("stop", id)
|
||||||
|
job.SetenvInt("t", 15)
|
||||||
|
if err := job.Run(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
25
server.go
25
server.go
|
@ -79,6 +79,10 @@ func jobInitApi(job *engine.Job) engine.Status {
|
||||||
job.Error(err)
|
job.Error(err)
|
||||||
return engine.StatusErr
|
return engine.StatusErr
|
||||||
}
|
}
|
||||||
|
if err := job.Eng.Register("stop", srv.ContainerStop); err != nil {
|
||||||
|
job.Error(err)
|
||||||
|
return engine.StatusErr
|
||||||
|
}
|
||||||
if err := job.Eng.Register("start", srv.ContainerStart); err != nil {
|
if err := job.Eng.Register("start", srv.ContainerStart); err != nil {
|
||||||
job.Error(err)
|
job.Error(err)
|
||||||
return engine.StatusErr
|
return engine.StatusErr
|
||||||
|
@ -1727,16 +1731,27 @@ func (srv *Server) ContainerStart(job *engine.Job) engine.Status {
|
||||||
return engine.StatusOK
|
return engine.StatusOK
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ContainerStop(name string, t int) error {
|
func (srv *Server) ContainerStop(job *engine.Job) engine.Status {
|
||||||
|
if len(job.Args) != 1 {
|
||||||
|
job.Errorf("Usage: %s CONTAINER\n", job.Name)
|
||||||
|
return engine.StatusErr
|
||||||
|
}
|
||||||
|
name := job.Args[0]
|
||||||
|
t := job.GetenvInt("t")
|
||||||
|
if t == -1 {
|
||||||
|
t = 10
|
||||||
|
}
|
||||||
if container := srv.runtime.Get(name); container != nil {
|
if container := srv.runtime.Get(name); container != nil {
|
||||||
if err := container.Stop(t); err != nil {
|
if err := container.Stop(int(t)); err != nil {
|
||||||
return fmt.Errorf("Cannot stop container %s: %s", name, err)
|
job.Errorf("Cannot stop container %s: %s\n", name, err)
|
||||||
|
return engine.StatusErr
|
||||||
}
|
}
|
||||||
srv.LogEvent("stop", container.ID, srv.runtime.repositories.ImageName(container.Image))
|
srv.LogEvent("stop", container.ID, srv.runtime.repositories.ImageName(container.Image))
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("No such container: %s", name)
|
job.Errorf("No such container: %s\n", name)
|
||||||
|
return engine.StatusErr
|
||||||
}
|
}
|
||||||
return nil
|
return engine.StatusOK
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ContainerWait(job *engine.Job) engine.Status {
|
func (srv *Server) ContainerWait(job *engine.Job) engine.Status {
|
||||||
|
|
Loading…
Reference in a new issue