diff --git a/daemon/daemon.go b/daemon/daemon.go index cc03c3d2a5..08e710b1c8 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -132,6 +132,9 @@ func (daemon *Daemon) Install(eng *engine.Engine) error { if err := eng.Register("start", daemon.ContainerStart); err != nil { return err } + if err := eng.Register("restart", daemon.ContainerRestart); err != nil { + return err + } return nil } diff --git a/daemon/restart.go b/daemon/restart.go new file mode 100644 index 0000000000..c0ae949a88 --- /dev/null +++ b/daemon/restart.go @@ -0,0 +1,27 @@ +package daemon + +import ( + "github.com/docker/docker/engine" +) + +func (daemon *Daemon) ContainerRestart(job *engine.Job) engine.Status { + if len(job.Args) != 1 { + return job.Errorf("Usage: %s CONTAINER\n", job.Name) + } + var ( + name = job.Args[0] + t = 10 + ) + if job.EnvExists("t") { + t = job.GetenvInt("t") + } + if container := daemon.Get(name); container != nil { + if err := container.Restart(int(t)); err != nil { + return job.Errorf("Cannot restart container %s: %s\n", name, err) + } + job.Eng.Job("log", "restart", container.ID, daemon.Repositories().ImageName(container.Image)).Run() + } else { + return job.Errorf("No such container: %s\n", name) + } + return engine.StatusOK +} diff --git a/server/container.go b/server/container.go index a0a05c867c..f8476e5c0a 100644 --- a/server/container.go +++ b/server/container.go @@ -261,28 +261,6 @@ func (srv *Server) ContainerCommit(job *engine.Job) engine.Status { return engine.StatusOK } -func (srv *Server) ContainerRestart(job *engine.Job) engine.Status { - if len(job.Args) != 1 { - return job.Errorf("Usage: %s CONTAINER\n", job.Name) - } - var ( - name = job.Args[0] - t = 10 - ) - if job.EnvExists("t") { - t = job.GetenvInt("t") - } - if container := srv.daemon.Get(name); container != nil { - if err := container.Restart(int(t)); err != nil { - return job.Errorf("Cannot restart container %s: %s\n", name, err) - } - srv.LogEvent("restart", container.ID, srv.daemon.Repositories().ImageName(container.Image)) - } else { - return job.Errorf("No such container: %s\n", name) - } - return engine.StatusOK -} - func (srv *Server) ContainerDestroy(job *engine.Job) engine.Status { if len(job.Args) != 1 { return job.Errorf("Not enough arguments. Usage: %s CONTAINER\n", job.Name) diff --git a/server/init.go b/server/init.go index 50718f1749..31c9e0419d 100644 --- a/server/init.go +++ b/server/init.go @@ -86,7 +86,6 @@ func InitServer(job *engine.Job) engine.Status { job.Eng.Hack_SetGlobalVar("httpapi.daemon", srv.daemon) for name, handler := range map[string]engine.Handler{ - "restart": srv.ContainerRestart, "wait": srv.ContainerWait, "tag": srv.ImageTag, // FIXME merge with "image_tag" "resize": srv.ContainerResize,