Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)
| ... | ... |
@@ -693,8 +693,11 @@ func postContainersStart(eng *engine.Engine, version version.Version, w http.Res |
| 693 | 693 |
if vars == nil {
|
| 694 | 694 |
return fmt.Errorf("Missing parameter")
|
| 695 | 695 |
} |
| 696 |
- name := vars["name"] |
|
| 697 |
- job := eng.Job("start", name)
|
|
| 696 |
+ var ( |
|
| 697 |
+ name = vars["name"] |
|
| 698 |
+ job = eng.Job("start", name)
|
|
| 699 |
+ ) |
|
| 700 |
+ |
|
| 698 | 701 |
// allow a nil body for backwards compatibility |
| 699 | 702 |
if r.Body != nil {
|
| 700 | 703 |
if api.MatchesContentType(r.Header.Get("Content-Type"), "application/json") {
|
| ... | ... |
@@ -704,6 +707,10 @@ func postContainersStart(eng *engine.Engine, version version.Version, w http.Res |
| 704 | 704 |
} |
| 705 | 705 |
} |
| 706 | 706 |
if err := job.Run(); err != nil {
|
| 707 |
+ if err.Error() == "Container already started" {
|
|
| 708 |
+ w.WriteHeader(http.StatusNotModified) |
|
| 709 |
+ return nil |
|
| 710 |
+ } |
|
| 707 | 711 |
return err |
| 708 | 712 |
} |
| 709 | 713 |
w.WriteHeader(http.StatusNoContent) |
| ... | ... |
@@ -720,6 +727,10 @@ func postContainersStop(eng *engine.Engine, version version.Version, w http.Resp |
| 720 | 720 |
job := eng.Job("stop", vars["name"])
|
| 721 | 721 |
job.Setenv("t", r.Form.Get("t"))
|
| 722 | 722 |
if err := job.Run(); err != nil {
|
| 723 |
+ if err.Error() == "Container already stopped" {
|
|
| 724 |
+ w.WriteHeader(http.StatusNotModified) |
|
| 725 |
+ return nil |
|
| 726 |
+ } |
|
| 723 | 727 |
return err |
| 724 | 728 |
} |
| 725 | 729 |
w.WriteHeader(http.StatusNoContent) |
| ... | ... |
@@ -21,7 +21,7 @@ page_keywords: API, Docker, rcli, REST, documentation |
| 21 | 21 |
The current version of the API is v1.13 |
| 22 | 22 |
|
| 23 | 23 |
Calling `/images/<name>/insert` is the same as calling |
| 24 |
-`/v1.12/images/<name>/insert`. |
|
| 24 |
+`/v1.13/images/<name>/insert`. |
|
| 25 | 25 |
|
| 26 | 26 |
You can still call an old version of the API using |
| 27 | 27 |
`/v1.12/images/<name>/insert`. |
| ... | ... |
@@ -38,6 +38,12 @@ You can still call an old version of the API using |
| 38 | 38 |
`Sockets` parameter added to the `/info` endpoint listing all the sockets the |
| 39 | 39 |
daemon is configured to listen on. |
| 40 | 40 |
|
| 41 |
+`POST /containers/(name)/start` |
|
| 42 |
+`POST /containers/(name)/stop` |
|
| 43 |
+ |
|
| 44 |
+**New!** |
|
| 45 |
+`start` and `stop` will now return 304 if the container's status is not modified |
|
| 46 |
+ |
|
| 41 | 47 |
## v1.12 |
| 42 | 48 |
|
| 43 | 49 |
### Full Documentation |
| ... | ... |
@@ -429,6 +429,7 @@ Start the container `id` |
| 429 | 429 |
Status Codes: |
| 430 | 430 |
|
| 431 | 431 |
- **204** – no error |
| 432 |
+ - **304** – container already started |
|
| 432 | 433 |
- **404** – no such container |
| 433 | 434 |
- **500** – server error |
| 434 | 435 |
|
| ... | ... |
@@ -455,6 +456,7 @@ Stop the container `id` |
| 455 | 455 |
Status Codes: |
| 456 | 456 |
|
| 457 | 457 |
- **204** – no error |
| 458 |
+ - **304** – container already stopped |
|
| 458 | 459 |
- **404** – no such container |
| 459 | 460 |
- **500** – server error |
| 460 | 461 |
|
| ... | ... |
@@ -2046,6 +2046,11 @@ func (srv *Server) ContainerStart(job *engine.Job) engine.Status {
|
| 2046 | 2046 |
if container == nil {
|
| 2047 | 2047 |
return job.Errorf("No such container: %s", name)
|
| 2048 | 2048 |
} |
| 2049 |
+ |
|
| 2050 |
+ if container.State.IsRunning() {
|
|
| 2051 |
+ return job.Errorf("Container already started")
|
|
| 2052 |
+ } |
|
| 2053 |
+ |
|
| 2049 | 2054 |
// If no environment was set, then no hostconfig was passed. |
| 2050 | 2055 |
if len(job.Environ()) > 0 {
|
| 2051 | 2056 |
hostConfig := runconfig.ContainerHostConfigFromJob(job) |
| ... | ... |
@@ -2099,6 +2104,9 @@ func (srv *Server) ContainerStop(job *engine.Job) engine.Status {
|
| 2099 | 2099 |
t = job.GetenvInt("t")
|
| 2100 | 2100 |
} |
| 2101 | 2101 |
if container := srv.daemon.Get(name); container != nil {
|
| 2102 |
+ if !container.State.IsRunning() {
|
|
| 2103 |
+ return job.Errorf("Container already stopped")
|
|
| 2104 |
+ } |
|
| 2102 | 2105 |
if err := container.Stop(int(t)); err != nil {
|
| 2103 | 2106 |
return job.Errorf("Cannot stop container %s: %s\n", name, err)
|
| 2104 | 2107 |
} |