зеркало из https://github.com/microsoft/docker.git
Merge pull request #2735 from shykes/engine-job-kill
New engine command: 'kill'
This commit is contained in:
Коммит
5fd3c8204d
16
api.go
16
api.go
|
@ -151,19 +151,11 @@ func postContainersKill(srv *Server, version float64, w http.ResponseWriter, r *
|
|||
if err := parseForm(r); err != nil {
|
||||
return err
|
||||
}
|
||||
name := vars["name"]
|
||||
|
||||
signal := 0
|
||||
if r != nil {
|
||||
if s := r.Form.Get("signal"); s != "" {
|
||||
s, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return err
|
||||
job := srv.Eng.Job("kill", vars["name"])
|
||||
if sig := r.Form.Get("signal"); sig != "" {
|
||||
job.Args = append(job.Args, sig)
|
||||
}
|
||||
signal = s
|
||||
}
|
||||
}
|
||||
if err := srv.ContainerKill(name, signal); err != nil {
|
||||
if err := job.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
|
|
|
@ -199,7 +199,7 @@ func TestCreateStartRestartStopStartKillRm(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := srv.ContainerKill(id, 0); err != nil {
|
||||
if err := eng.Job("kill", id).Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ func containerWaitTimeout(eng *engine.Engine, id string, t utils.Fataler) error
|
|||
}
|
||||
|
||||
func containerKill(eng *engine.Engine, id string, t utils.Fataler) {
|
||||
if err := getContainer(eng, id, t).Kill(); err != nil {
|
||||
if err := eng.Job("kill", id).Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
35
server.go
35
server.go
|
@ -22,6 +22,7 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
@ -82,6 +83,10 @@ func jobInitApi(job *engine.Job) engine.Status {
|
|||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
if err := job.Eng.Register("kill", srv.ContainerKill); err != nil {
|
||||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
if err := job.Eng.Register("serveapi", srv.ListenAndServe); err != nil {
|
||||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
|
@ -148,25 +153,43 @@ func (v *simpleVersionInfo) Version() string {
|
|||
// If no signal is given (sig 0), then Kill with SIGKILL and wait
|
||||
// for the container to exit.
|
||||
// If a signal is given, then just send it to the container and return.
|
||||
func (srv *Server) ContainerKill(name string, sig int) error {
|
||||
func (srv *Server) ContainerKill(job *engine.Job) engine.Status {
|
||||
if n := len(job.Args); n < 1 || n > 2 {
|
||||
job.Errorf("Usage: %s CONTAINER [SIGNAL]", job.Name)
|
||||
return engine.StatusErr
|
||||
}
|
||||
name := job.Args[0]
|
||||
var sig uint64
|
||||
if len(job.Args) == 2 && job.Args[1] != "" {
|
||||
var err error
|
||||
// The largest legal signal is 31, so let's parse on 5 bits
|
||||
sig, err = strconv.ParseUint(job.Args[1], 10, 5)
|
||||
if err != nil {
|
||||
job.Errorf("Invalid signal: %s", job.Args[1])
|
||||
return engine.StatusErr
|
||||
}
|
||||
}
|
||||
if container := srv.runtime.Get(name); container != nil {
|
||||
// If no signal is passed, perform regular Kill (SIGKILL + wait())
|
||||
if sig == 0 {
|
||||
if err := container.Kill(); err != nil {
|
||||
return fmt.Errorf("Cannot kill container %s: %s", name, err)
|
||||
job.Errorf("Cannot kill container %s: %s", name, err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
srv.LogEvent("kill", container.ID, srv.runtime.repositories.ImageName(container.Image))
|
||||
} else {
|
||||
// Otherwise, just send the requested signal
|
||||
if err := container.kill(sig); err != nil {
|
||||
return fmt.Errorf("Cannot kill container %s: %s", name, err)
|
||||
if err := container.kill(int(sig)); err != nil {
|
||||
job.Errorf("Cannot kill container %s: %s", name, err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
// FIXME: Add event for signals
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("No such container: %s", name)
|
||||
job.Errorf("No such container: %s", name)
|
||||
return engine.StatusErr
|
||||
}
|
||||
return nil
|
||||
return engine.StatusOK
|
||||
}
|
||||
|
||||
func (srv *Server) ContainerExport(job *engine.Job) engine.Status {
|
||||
|
|
Загрузка…
Ссылка в новой задаче