github.com/demonoid81/containerd@v1.3.4/runtime/v2/example/example.go (about) 1 // +build linux 2 3 /* 4 Copyright The containerd Authors. 5 6 Licensed under the Apache License, Version 2.0 (the "License"); 7 you may not use this file except in compliance with the License. 8 You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 See the License for the specific language governing permissions and 16 limitations under the License. 17 */ 18 19 package example 20 21 import ( 22 "context" 23 "os" 24 25 "github.com/containerd/containerd/errdefs" 26 "github.com/containerd/containerd/runtime/v2/shim" 27 taskAPI "github.com/containerd/containerd/runtime/v2/task" 28 ptypes "github.com/gogo/protobuf/types" 29 ) 30 31 var ( 32 // check to make sure the *service implements the GRPC API 33 _ = (taskAPI.TaskService)(&service{}) 34 // common response type 35 empty = &ptypes.Empty{} 36 ) 37 38 // New returns a new shim service 39 func New(ctx context.Context, id string, publisher shim.Publisher, shutdown func()) (shim.Shim, error) { 40 return &service{}, nil 41 } 42 43 type service struct { 44 } 45 46 // StartShim is a binary call that executes a new shim returning the address 47 func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (string, error) { 48 return "", nil 49 } 50 51 // Cleanup is a binary call that cleans up any resources used by the shim when the service crashes 52 func (s *service) Cleanup(ctx context.Context) (*taskAPI.DeleteResponse, error) { 53 return nil, errdefs.ErrNotImplemented 54 } 55 56 // Create a new container 57 func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ *taskAPI.CreateTaskResponse, err error) { 58 return nil, errdefs.ErrNotImplemented 59 } 60 61 // Start the primary user process inside the container 62 func (s *service) Start(ctx context.Context, r *taskAPI.StartRequest) (*taskAPI.StartResponse, error) { 63 return nil, errdefs.ErrNotImplemented 64 } 65 66 // Delete a process or container 67 func (s *service) Delete(ctx context.Context, r *taskAPI.DeleteRequest) (*taskAPI.DeleteResponse, error) { 68 return nil, errdefs.ErrNotImplemented 69 } 70 71 // Exec an additional process inside the container 72 func (s *service) Exec(ctx context.Context, r *taskAPI.ExecProcessRequest) (*ptypes.Empty, error) { 73 return nil, errdefs.ErrNotImplemented 74 } 75 76 // ResizePty of a process 77 func (s *service) ResizePty(ctx context.Context, r *taskAPI.ResizePtyRequest) (*ptypes.Empty, error) { 78 return nil, errdefs.ErrNotImplemented 79 } 80 81 // State returns runtime state of a process 82 func (s *service) State(ctx context.Context, r *taskAPI.StateRequest) (*taskAPI.StateResponse, error) { 83 return nil, errdefs.ErrNotImplemented 84 } 85 86 // Pause the container 87 func (s *service) Pause(ctx context.Context, r *taskAPI.PauseRequest) (*ptypes.Empty, error) { 88 return nil, errdefs.ErrNotImplemented 89 } 90 91 // Resume the container 92 func (s *service) Resume(ctx context.Context, r *taskAPI.ResumeRequest) (*ptypes.Empty, error) { 93 return nil, errdefs.ErrNotImplemented 94 } 95 96 // Kill a process 97 func (s *service) Kill(ctx context.Context, r *taskAPI.KillRequest) (*ptypes.Empty, error) { 98 return nil, errdefs.ErrNotImplemented 99 } 100 101 // Pids returns all pids inside the container 102 func (s *service) Pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskAPI.PidsResponse, error) { 103 return nil, errdefs.ErrNotImplemented 104 } 105 106 // CloseIO of a process 107 func (s *service) CloseIO(ctx context.Context, r *taskAPI.CloseIORequest) (*ptypes.Empty, error) { 108 return nil, errdefs.ErrNotImplemented 109 } 110 111 // Checkpoint the container 112 func (s *service) Checkpoint(ctx context.Context, r *taskAPI.CheckpointTaskRequest) (*ptypes.Empty, error) { 113 return nil, errdefs.ErrNotImplemented 114 } 115 116 // Connect returns shim information of the underlying service 117 func (s *service) Connect(ctx context.Context, r *taskAPI.ConnectRequest) (*taskAPI.ConnectResponse, error) { 118 return nil, errdefs.ErrNotImplemented 119 } 120 121 // Shutdown is called after the underlying resources of the shim are cleaned up and the service can be stopped 122 func (s *service) Shutdown(ctx context.Context, r *taskAPI.ShutdownRequest) (*ptypes.Empty, error) { 123 os.Exit(0) 124 return empty, nil 125 } 126 127 // Stats returns container level system stats for a container and its processes 128 func (s *service) Stats(ctx context.Context, r *taskAPI.StatsRequest) (*taskAPI.StatsResponse, error) { 129 return nil, errdefs.ErrNotImplemented 130 } 131 132 // Update the live container 133 func (s *service) Update(ctx context.Context, r *taskAPI.UpdateTaskRequest) (*ptypes.Empty, error) { 134 return nil, errdefs.ErrNotImplemented 135 } 136 137 // Wait for a process to exit 138 func (s *service) Wait(ctx context.Context, r *taskAPI.WaitRequest) (*taskAPI.WaitResponse, error) { 139 return nil, errdefs.ErrNotImplemented 140 }