diff --git a/api/api.go b/api/api.go index 9b01c3ad9a..86948b17c2 100644 --- a/api/api.go +++ b/api/api.go @@ -137,6 +137,21 @@ func postContainersStart(c *context, w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "{%q:%q}", "Id", container.Id) } +// POST /containers/{name:.*}/kill +func postContainerKill(c *context, w http.ResponseWriter, r *http.Request) { + name := mux.Vars(r)["name"] + container := c.cluster.Container(name) + if container == nil { + http.Error(w, fmt.Sprintf("Container %s not found", name), http.StatusNotFound) + return + } + + if err := container.Kill(r.Form.Get("signal")); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + fmt.Fprintf(w, "{%q:%q}", "Id", container.Id) +} + // POST /containers/{name:.*}/pause func postContainerPause(c *context, w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] @@ -268,7 +283,7 @@ func createRouter(c *context, enableCors bool) (*mux.Router, error) { "/images/{name:.*}/push": notImplementedHandler, "/images/{name:.*}/tag": notImplementedHandler, "/containers/create": postContainersCreate, - "/containers/{name:.*}/kill": notImplementedHandler, + "/containers/{name:.*}/kill": postContainerKill, "/containers/{name:.*}/pause": postContainerPause, "/containers/{name:.*}/unpause": postContainerUnpause, "/containers/{name:.*}/restart": notImplementedHandler, diff --git a/cluster/container.go b/cluster/container.go index 6348070c47..7a15010f4f 100644 --- a/cluster/container.go +++ b/cluster/container.go @@ -17,8 +17,8 @@ func (c *Container) Start() error { return c.node.client.StartContainer(c.Id, nil) } -func (c *Container) Kill(sig int) error { - return c.node.client.KillContainer(c.Id) +func (c *Container) Kill(signal string) error { + return c.node.client.KillContainer(c.Id, signal) } func (c *Container) Stop() error {