Signed-off-by: Antonio Murdaca <me@runcom.ninja>
| ... | ... |
@@ -988,9 +988,14 @@ func postContainersStop(eng *engine.Engine, version version.Version, w http.Resp |
| 988 | 988 |
if vars == nil {
|
| 989 | 989 |
return fmt.Errorf("Missing parameter")
|
| 990 | 990 |
} |
| 991 |
- job := eng.Job("stop", vars["name"])
|
|
| 992 |
- job.Setenv("t", r.Form.Get("t"))
|
|
| 993 |
- if err := job.Run(); err != nil {
|
|
| 991 |
+ |
|
| 992 |
+ d := getDaemon(eng) |
|
| 993 |
+ seconds, err := strconv.Atoi(r.Form.Get("t"))
|
|
| 994 |
+ if err != nil {
|
|
| 995 |
+ return err |
|
| 996 |
+ } |
|
| 997 |
+ |
|
| 998 |
+ if err := d.ContainerStop(vars["name"], seconds); err != nil {
|
|
| 994 | 999 |
if err.Error() == "Container already stopped" {
|
| 995 | 1000 |
w.WriteHeader(http.StatusNotModified) |
| 996 | 1001 |
return nil |
| ... | ... |
@@ -998,6 +1003,7 @@ func postContainersStop(eng *engine.Engine, version version.Version, w http.Resp |
| 998 | 998 |
return err |
| 999 | 999 |
} |
| 1000 | 1000 |
w.WriteHeader(http.StatusNoContent) |
| 1001 |
+ |
|
| 1001 | 1002 |
return nil |
| 1002 | 1003 |
} |
| 1003 | 1004 |
|
| ... | ... |
@@ -126,7 +126,6 @@ func (daemon *Daemon) Install(eng *engine.Engine) error {
|
| 126 | 126 |
"logs": daemon.ContainerLogs, |
| 127 | 127 |
"restart": daemon.ContainerRestart, |
| 128 | 128 |
"start": daemon.ContainerStart, |
| 129 |
- "stop": daemon.ContainerStop, |
|
| 130 | 129 |
"execCreate": daemon.ContainerExecCreate, |
| 131 | 130 |
"execStart": daemon.ContainerExecStart, |
| 132 | 131 |
"execInspect": daemon.ContainerExecInspect, |
| ... | ... |
@@ -1,22 +1,8 @@ |
| 1 | 1 |
package daemon |
| 2 | 2 |
|
| 3 |
-import ( |
|
| 4 |
- "fmt" |
|
| 3 |
+import "fmt" |
|
| 5 | 4 |
|
| 6 |
- "github.com/docker/docker/engine" |
|
| 7 |
-) |
|
| 8 |
- |
|
| 9 |
-func (daemon *Daemon) ContainerStop(job *engine.Job) error {
|
|
| 10 |
- if len(job.Args) != 1 {
|
|
| 11 |
- return fmt.Errorf("Usage: %s CONTAINER\n", job.Name)
|
|
| 12 |
- } |
|
| 13 |
- var ( |
|
| 14 |
- name = job.Args[0] |
|
| 15 |
- t = 10 |
|
| 16 |
- ) |
|
| 17 |
- if job.EnvExists("t") {
|
|
| 18 |
- t = job.GetenvInt("t")
|
|
| 19 |
- } |
|
| 5 |
+func (daemon *Daemon) ContainerStop(name string, seconds int) error {
|
|
| 20 | 6 |
container, err := daemon.Get(name) |
| 21 | 7 |
if err != nil {
|
| 22 | 8 |
return err |
| ... | ... |
@@ -24,7 +10,7 @@ func (daemon *Daemon) ContainerStop(job *engine.Job) error {
|
| 24 | 24 |
if !container.IsRunning() {
|
| 25 | 25 |
return fmt.Errorf("Container already stopped")
|
| 26 | 26 |
} |
| 27 |
- if err := container.Stop(int(t)); err != nil {
|
|
| 27 |
+ if err := container.Stop(seconds); err != nil {
|
|
| 28 | 28 |
return fmt.Errorf("Cannot stop container %s: %s\n", name, err)
|
| 29 | 29 |
} |
| 30 | 30 |
container.LogEvent("stop")
|