@@ -49,9 +49,7 @@ import (
4949)
5050
5151const (
52- runhcsBinary = "runhcs"
53- runhcsVersion = "0.0.1"
54- runhcsDebugLegacy = "--debug" // TODO: JTERRY75 remove when all cmd's are complete in go-runhcs
52+ runhcsShimVersion = "0.0.1"
5553)
5654
5755var (
@@ -201,41 +199,9 @@ func (s *service) State(ctx context.Context, r *taskAPI.StateRequest) (*taskAPI.
201199 return nil , err
202200 }
203201
204- cmd := exec .Command (runhcsBinary , runhcsDebugLegacy , "state" , p .id )
205- sout := getBuffer ()
206- defer putBuffer (sout )
207-
208- cmd .Stdout = sout
209- _ , stateErr := runCmd (ctx , cmd )
210- if stateErr != nil {
211- return nil , stateErr
212- }
213-
214- // TODO: JTERRY75 merge this with runhcs declaration
215- type containerState struct {
216- // Version is the OCI version for the container
217- Version string `json:"ociVersion"`
218- // ID is the container ID
219- ID string `json:"id"`
220- // InitProcessPid is the init process id in the parent namespace
221- InitProcessPid int `json:"pid"`
222- // Status is the current status of the container, running, paused, ...
223- Status string `json:"status"`
224- // Bundle is the path on the filesystem to the bundle
225- Bundle string `json:"bundle"`
226- // Rootfs is a path to a directory containing the container's root filesystem.
227- Rootfs string `json:"rootfs"`
228- // Created is the unix timestamp for the creation time of the container in UTC
229- Created time.Time `json:"created"`
230- // Annotations is the user defined annotations added to the config.
231- Annotations map [string ]string `json:"annotations,omitempty"`
232- // The owner of the state directory (the owner of the container).
233- Owner string `json:"owner"`
234- }
235-
236- var cs containerState
237- if err := json .NewDecoder (sout ).Decode (& cs ); err != nil {
238- log .G (ctx ).WithError (err ).Debugf ("failed to decode runhcs state output: %s" , sout .Bytes ())
202+ rhcs := newRunhcs (p .bundle )
203+ cs , err := rhcs .State (ctx , p .id )
204+ if err != nil {
239205 return nil , err
240206 }
241207
@@ -551,13 +517,14 @@ func (s *service) Pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskAPI.Pi
551517// Pause the container
552518func (s * service ) Pause (ctx context.Context , r * taskAPI.PauseRequest ) (* ptypes.Empty , error ) {
553519 // TODO: Validate that 'id' is actually a valid parent container ID
554- if _ , err := s .getProcess (r .ID , "" ); err != nil {
520+ var p * process
521+ var err error
522+ if p , err = s .getProcess (r .ID , "" ); err != nil {
555523 return nil , err
556524 }
557525
558- cmd := exec .Command (runhcsBinary , runhcsDebugLegacy , "pause" , r .ID )
559- _ , err := runCmd (ctx , cmd )
560- if err != nil {
526+ rhcs := newRunhcs (p .bundle )
527+ if err = rhcs .Pause (ctx , p .id ); err != nil {
561528 return nil , err
562529 }
563530
@@ -567,13 +534,14 @@ func (s *service) Pause(ctx context.Context, r *taskAPI.PauseRequest) (*ptypes.E
567534// Resume the container
568535func (s * service ) Resume (ctx context.Context , r * taskAPI.ResumeRequest ) (* ptypes.Empty , error ) {
569536 // TODO: Validate that 'id' is actually a valid parent container ID
570- if _ , err := s .getProcess (r .ID , "" ); err != nil {
537+ var p * process
538+ var err error
539+ if p , err = s .getProcess (r .ID , "" ); err != nil {
571540 return nil , err
572541 }
573542
574- cmd := exec .Command (runhcsBinary , runhcsDebugLegacy , "resume" , r .ID )
575- _ , err := runCmd (ctx , cmd )
576- if err != nil {
543+ rhcs := newRunhcs (p .bundle )
544+ if err = rhcs .Resume (ctx , p .id ); err != nil {
577545 return nil , err
578546 }
579547
@@ -599,7 +567,7 @@ func (s *service) Kill(ctx context.Context, r *taskAPI.KillRequest) (*ptypes.Emp
599567 // TODO: JTERRY75 runhcs support for r.All?
600568 rhcs := newRunhcs (p .bundle )
601569 if err = rhcs .Kill (ctx , p .id , strconv .FormatUint (uint64 (r .Signal ), 10 )); err != nil {
602- if ! strings .Contains (err .Error (), "container is not running " ) {
570+ if ! strings .Contains (err .Error (), "container is stopped " ) {
603571 return nil , err
604572 }
605573 }
@@ -698,18 +666,12 @@ func (s *service) ResizePty(ctx context.Context, r *taskAPI.ResizePtyRequest) (*
698666 return nil , err
699667 }
700668
701- cmd := exec .Command (
702- runhcsBinary ,
703- runhcsDebugLegacy ,
704- "resize-tty" ,
705- p .cid ,
706- "-p" ,
707- strconv .FormatUint (uint64 (p .pid ), 10 ),
708- strconv .FormatUint (uint64 (r .Width ), 10 ),
709- strconv .FormatUint (uint64 (r .Height ), 10 ))
710-
711- _ , err = runCmd (ctx , cmd )
712- if err != nil {
669+ pid := int (p .pid )
670+ opts := runhcs.ResizeTTYOpts {
671+ Pid : & pid ,
672+ }
673+ rhcs := newRunhcs (p .bundle )
674+ if err = rhcs .ResizeTTY (ctx , p .cid , uint16 (r .Width ), uint16 (r .Height ), & opts ); err != nil {
713675 return nil , err
714676 }
715677
@@ -756,7 +718,7 @@ func (s *service) Connect(ctx context.Context, r *taskAPI.ConnectRequest) (*task
756718 return & taskAPI.ConnectResponse {
757719 ShimPid : uint32 (os .Getpid ()),
758720 TaskPid : s .processes [s .id ].pid ,
759- Version : runhcsVersion ,
721+ Version : runhcsShimVersion ,
760722 }, nil
761723}
762724
0 commit comments