mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
use exists
Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
parent
28b5ae8cc4
commit
1498cd4e05
3 changed files with 18 additions and 18 deletions
12
api.go
12
api.go
|
@ -584,11 +584,7 @@ func postContainersRestart(srv *Server, version float64, w http.ResponseWriter,
|
||||||
return fmt.Errorf("Missing parameter")
|
return fmt.Errorf("Missing parameter")
|
||||||
}
|
}
|
||||||
job := srv.Eng.Job("restart", vars["name"])
|
job := srv.Eng.Job("restart", vars["name"])
|
||||||
if r.Form.Get("t") == "" {
|
job.Setenv("t", r.Form.Get("t"))
|
||||||
job.Setenv("t", "-1")
|
|
||||||
} else {
|
|
||||||
job.Setenv("t", r.Form.Get("t"))
|
|
||||||
}
|
|
||||||
if err := job.Run(); err != nil {
|
if err := job.Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -656,11 +652,7 @@ func postContainersStop(srv *Server, version float64, w http.ResponseWriter, r *
|
||||||
return fmt.Errorf("Missing parameter")
|
return fmt.Errorf("Missing parameter")
|
||||||
}
|
}
|
||||||
job := srv.Eng.Job("stop", vars["name"])
|
job := srv.Eng.Job("stop", vars["name"])
|
||||||
if r.Form.Get("t") == "" {
|
job.Setenv("t", r.Form.Get("t"))
|
||||||
job.Setenv("t", "-1")
|
|
||||||
} else {
|
|
||||||
job.Setenv("t", r.Form.Get("t"))
|
|
||||||
}
|
|
||||||
if err := job.Run(); err != nil {
|
if err := job.Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,10 @@ func (job *Job) String() string {
|
||||||
return fmt.Sprintf("%s.%s%s", job.Eng, job.CallString(), job.StatusString())
|
return fmt.Sprintf("%s.%s%s", job.Eng, job.CallString(), job.StatusString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (job *Job) EnvExists(key string) (value bool) {
|
||||||
|
return job.env.Exists(key)
|
||||||
|
}
|
||||||
|
|
||||||
func (job *Job) Getenv(key string) (value string) {
|
func (job *Job) Getenv(key string) (value string) {
|
||||||
return job.env.Get(key)
|
return job.env.Get(key)
|
||||||
}
|
}
|
||||||
|
|
20
server.go
20
server.go
|
@ -1798,10 +1798,12 @@ func (srv *Server) ContainerRestart(job *engine.Job) engine.Status {
|
||||||
job.Errorf("Usage: %s CONTAINER\n", job.Name)
|
job.Errorf("Usage: %s CONTAINER\n", job.Name)
|
||||||
return engine.StatusErr
|
return engine.StatusErr
|
||||||
}
|
}
|
||||||
name := job.Args[0]
|
var (
|
||||||
t := job.GetenvInt("t")
|
name = job.Args[0]
|
||||||
if t == -1 {
|
t = 10
|
||||||
t = 10
|
)
|
||||||
|
if job.EnvExists("t") {
|
||||||
|
t = job.GetenvInt("t")
|
||||||
}
|
}
|
||||||
if container := srv.runtime.Get(name); container != nil {
|
if container := srv.runtime.Get(name); container != nil {
|
||||||
if err := container.Restart(int(t)); err != nil {
|
if err := container.Restart(int(t)); err != nil {
|
||||||
|
@ -2239,10 +2241,12 @@ func (srv *Server) ContainerStop(job *engine.Job) engine.Status {
|
||||||
job.Errorf("Usage: %s CONTAINER\n", job.Name)
|
job.Errorf("Usage: %s CONTAINER\n", job.Name)
|
||||||
return engine.StatusErr
|
return engine.StatusErr
|
||||||
}
|
}
|
||||||
name := job.Args[0]
|
var (
|
||||||
t := job.GetenvInt("t")
|
name = job.Args[0]
|
||||||
if t == -1 {
|
t = 10
|
||||||
t = 10
|
)
|
||||||
|
if job.EnvExists("t") {
|
||||||
|
t = job.GetenvInt("t")
|
||||||
}
|
}
|
||||||
if container := srv.runtime.Get(name); container != nil {
|
if container := srv.runtime.Get(name); container != nil {
|
||||||
if err := container.Stop(int(t)); err != nil {
|
if err := container.Stop(int(t)); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue