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)
|
||||||
|
|
|
@ -24,7 +24,7 @@ type Job struct {
|
||||||
Eng *Engine
|
Eng *Engine
|
||||||
Name string
|
Name string
|
||||||
Args []string
|
Args []string
|
||||||
env *Env
|
env *Env
|
||||||
Stdout *Output
|
Stdout *Output
|
||||||
Stderr *Output
|
Stderr *Output
|
||||||
Stdin *Input
|
Stdin *Input
|
||||||
|
|
|
@ -168,7 +168,7 @@ func Tail(src io.Reader, n int, dst *[]string) {
|
||||||
// AddEnv starts a new goroutine which will decode all subsequent data
|
// AddEnv starts a new goroutine which will decode all subsequent data
|
||||||
// as a stream of json-encoded objects, and point `dst` to the last
|
// as a stream of json-encoded objects, and point `dst` to the last
|
||||||
// decoded object.
|
// decoded object.
|
||||||
// The result `env` can be queried using the type-neutral Env interface.
|
// The result `env` can be queried using the type-neutral Env interface.
|
||||||
// It is not safe to query `env` until the Output is closed.
|
// It is not safe to query `env` until the Output is closed.
|
||||||
func (o *Output) AddEnv() (dst *Env, err error) {
|
func (o *Output) AddEnv() (dst *Env, err error) {
|
||||||
src, err := o.AddPipe()
|
src, err := o.AddPipe()
|
||||||
|
@ -185,9 +185,8 @@ func (o *Output) AddEnv() (dst *Env, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
*dst= *env
|
*dst = *env
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
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