github.com/demonoid81/containerd@v1.3.4/runtime/task.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package runtime 18 19 import ( 20 "context" 21 "time" 22 23 "github.com/gogo/protobuf/types" 24 ) 25 26 // TaskInfo provides task specific information 27 type TaskInfo struct { 28 ID string 29 Runtime string 30 Spec []byte 31 Namespace string 32 } 33 34 // Process is a runtime object for an executing process inside a container 35 type Process interface { 36 // ID of the process 37 ID() string 38 // State returns the process state 39 State(context.Context) (State, error) 40 // Kill signals a container 41 Kill(context.Context, uint32, bool) error 42 // Pty resizes the processes pty/console 43 ResizePty(context.Context, ConsoleSize) error 44 // CloseStdin closes the processes stdin 45 CloseIO(context.Context) error 46 // Start the container's user defined process 47 Start(context.Context) error 48 // Wait for the process to exit 49 Wait(context.Context) (*Exit, error) 50 // Delete deletes the process 51 Delete(context.Context) (*Exit, error) 52 } 53 54 // Task is the runtime object for an executing container 55 type Task interface { 56 Process 57 58 // PID of the process 59 PID() uint32 60 // Namespace that the task exists in 61 Namespace() string 62 // Pause pauses the container process 63 Pause(context.Context) error 64 // Resume unpauses the container process 65 Resume(context.Context) error 66 // Exec adds a process into the container 67 Exec(context.Context, string, ExecOpts) (Process, error) 68 // Pids returns all pids 69 Pids(context.Context) ([]ProcessInfo, error) 70 // Checkpoint checkpoints a container to an image with live system data 71 Checkpoint(context.Context, string, *types.Any) error 72 // Update sets the provided resources to a running task 73 Update(context.Context, *types.Any) error 74 // Process returns a process within the task for the provided id 75 Process(context.Context, string) (Process, error) 76 // Stats returns runtime specific metrics for a task 77 Stats(context.Context) (*types.Any, error) 78 } 79 80 // ExecOpts provides additional options for additional processes running in a task 81 type ExecOpts struct { 82 Spec *types.Any 83 IO IO 84 } 85 86 // ConsoleSize of a pty or windows terminal 87 type ConsoleSize struct { 88 Width uint32 89 Height uint32 90 } 91 92 // Status is the runtime status of a task and/or process 93 type Status int 94 95 const ( 96 // CreatedStatus when a process has been created 97 CreatedStatus Status = iota + 1 98 // RunningStatus when a process is running 99 RunningStatus 100 // StoppedStatus when a process has stopped 101 StoppedStatus 102 // DeletedStatus when a process has been deleted 103 DeletedStatus 104 // PausedStatus when a process is paused 105 PausedStatus 106 // PausingStatus when a process is currently pausing 107 PausingStatus 108 ) 109 110 // State information for a process 111 type State struct { 112 // Status is the current status of the container 113 Status Status 114 // Pid is the main process id for the container 115 Pid uint32 116 // ExitStatus of the process 117 // Only valid if the Status is Stopped 118 ExitStatus uint32 119 // ExitedAt is the time at which the process exited 120 // Only valid if the Status is Stopped 121 ExitedAt time.Time 122 Stdin string 123 Stdout string 124 Stderr string 125 Terminal bool 126 } 127 128 // ProcessInfo holds platform specific process information 129 type ProcessInfo struct { 130 // Pid is the process ID 131 Pid uint32 132 // Info includes additional process information 133 // Info varies by platform 134 Info interface{} 135 }