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 19package example 20 21import ( 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 31var ( 32 // check to make sure the *service implements the GRPC API 33 _ = (taskAPI.TaskService)(&service{}) 34) 35 36// New returns a new shim service 37func New(ctx context.Context, id string, publisher shim.Publisher, shutdown func()) (shim.Shim, error) { 38 return &service{}, nil 39} 40 41type service struct { 42} 43 44// StartShim is a binary call that executes a new shim returning the address 45func (s *service) StartShim(ctx context.Context, opts shim.StartOpts) (string, error) { 46 return "", nil 47} 48 49// Cleanup is a binary call that cleans up any resources used by the shim when the service crashes 50func (s *service) Cleanup(ctx context.Context) (*taskAPI.DeleteResponse, error) { 51 return nil, errdefs.ErrNotImplemented 52} 53 54// Create a new container 55func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ *taskAPI.CreateTaskResponse, err error) { 56 return nil, errdefs.ErrNotImplemented 57} 58 59// Start the primary user process inside the container 60func (s *service) Start(ctx context.Context, r *taskAPI.StartRequest) (*taskAPI.StartResponse, error) { 61 return nil, errdefs.ErrNotImplemented 62} 63 64// Delete a process or container 65func (s *service) Delete(ctx context.Context, r *taskAPI.DeleteRequest) (*taskAPI.DeleteResponse, error) { 66 return nil, errdefs.ErrNotImplemented 67} 68 69// Exec an additional process inside the container 70func (s *service) Exec(ctx context.Context, r *taskAPI.ExecProcessRequest) (*ptypes.Empty, error) { 71 return nil, errdefs.ErrNotImplemented 72} 73 74// ResizePty of a process 75func (s *service) ResizePty(ctx context.Context, r *taskAPI.ResizePtyRequest) (*ptypes.Empty, error) { 76 return nil, errdefs.ErrNotImplemented 77} 78 79// State returns runtime state of a process 80func (s *service) State(ctx context.Context, r *taskAPI.StateRequest) (*taskAPI.StateResponse, error) { 81 return nil, errdefs.ErrNotImplemented 82} 83 84// Pause the container 85func (s *service) Pause(ctx context.Context, r *taskAPI.PauseRequest) (*ptypes.Empty, error) { 86 return nil, errdefs.ErrNotImplemented 87} 88 89// Resume the container 90func (s *service) Resume(ctx context.Context, r *taskAPI.ResumeRequest) (*ptypes.Empty, error) { 91 return nil, errdefs.ErrNotImplemented 92} 93 94// Kill a process 95func (s *service) Kill(ctx context.Context, r *taskAPI.KillRequest) (*ptypes.Empty, error) { 96 return nil, errdefs.ErrNotImplemented 97} 98 99// Pids returns all pids inside the container 100func (s *service) Pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskAPI.PidsResponse, error) { 101 return nil, errdefs.ErrNotImplemented 102} 103 104// CloseIO of a process 105func (s *service) CloseIO(ctx context.Context, r *taskAPI.CloseIORequest) (*ptypes.Empty, error) { 106 return nil, errdefs.ErrNotImplemented 107} 108 109// Checkpoint the container 110func (s *service) Checkpoint(ctx context.Context, r *taskAPI.CheckpointTaskRequest) (*ptypes.Empty, error) { 111 return nil, errdefs.ErrNotImplemented 112} 113 114// Connect returns shim information of the underlying service 115func (s *service) Connect(ctx context.Context, r *taskAPI.ConnectRequest) (*taskAPI.ConnectResponse, error) { 116 return nil, errdefs.ErrNotImplemented 117} 118 119// Shutdown is called after the underlying resources of the shim are cleaned up and the service can be stopped 120func (s *service) Shutdown(ctx context.Context, r *taskAPI.ShutdownRequest) (*ptypes.Empty, error) { 121 os.Exit(0) 122 return &ptypes.Empty{}, nil 123} 124 125// Stats returns container level system stats for a container and its processes 126func (s *service) Stats(ctx context.Context, r *taskAPI.StatsRequest) (*taskAPI.StatsResponse, error) { 127 return nil, errdefs.ErrNotImplemented 128} 129 130// Update the live container 131func (s *service) Update(ctx context.Context, r *taskAPI.UpdateTaskRequest) (*ptypes.Empty, error) { 132 return nil, errdefs.ErrNotImplemented 133} 134 135// Wait for a process to exit 136func (s *service) Wait(ctx context.Context, r *taskAPI.WaitRequest) (*taskAPI.WaitResponse, error) { 137 return nil, errdefs.ErrNotImplemented 138} 139