From 0741159ce8e598c7073b26028f84f9a9b3b012f6 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Mon, 12 Sep 2016 15:43:11 -0700 Subject: [PATCH 1/2] Set the started time for a container Signed-off-by: Mrunal Patel --- oci/oci.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/oci/oci.go b/oci/oci.go index 3175ab91..9d875211 100644 --- a/oci/oci.go +++ b/oci/oci.go @@ -73,7 +73,11 @@ func (r *Runtime) CreateContainer(c *Container) error { // StartContainer starts a container. func (r *Runtime) StartContainer(c *Container) error { - return utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, r.path, "start", c.name) + if err := utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, r.path, "start", c.name); err != nil { + return err + } + c.state.Started = time.Now() + return nil } // StopContainer stops a container. @@ -119,6 +123,7 @@ type Container struct { type ContainerState struct { specs.State Created time.Time `json:"created"` + Started time.Time `json:"started"` } // NewContainer creates a container object. From 819db7d8cca66fd37b2305843693e220cf433e3f Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Mon, 12 Sep 2016 15:43:30 -0700 Subject: [PATCH 2/2] Return the started time and ctr state with ctr status Signed-off-by: Mrunal Patel --- server/runtime.go | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/server/runtime.go b/server/runtime.go index 20cf4445..b3cdbab9 100644 --- a/server/runtime.go +++ b/server/runtime.go @@ -643,16 +643,38 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq return nil, err } - cState := s.runtime.ContainerStatus(c) - created := cState.Created.Unix() - - return &pb.ContainerStatusResponse{ + csr := &pb.ContainerStatusResponse{ Status: &pb.ContainerStatus{ - Id: containerName, - CreatedAt: int64Ptr(created), + Id: containerName, }, - }, nil - return nil, nil + } + + cState := s.runtime.ContainerStatus(c) + rStatus := pb.ContainerState_UNKNOWN + + switch cState.Status { + case "created": + rStatus = pb.ContainerState_CREATED + created := cState.Created.Unix() + csr.Status.CreatedAt = int64Ptr(created) + case "running": + rStatus = pb.ContainerState_RUNNING + created := cState.Created.Unix() + csr.Status.CreatedAt = int64Ptr(created) + started := cState.Started.Unix() + csr.Status.StartedAt = int64Ptr(started) + case "stopped": + // TODO: Get the exit time + rStatus = pb.ContainerState_EXITED + created := cState.Created.Unix() + csr.Status.CreatedAt = int64Ptr(created) + started := cState.Started.Unix() + csr.Status.StartedAt = int64Ptr(started) + } + + csr.Status.State = &rStatus + + return csr, nil } // Exec executes the command in the container.