MCPcopy Create free account
hub / github.com/containerd/nerdctl / killContainer

Function killContainer

pkg/cmd/container/kill.go:82–127  ·  view source on GitHub ↗
(ctx context.Context, container containerd.Container, signal syscall.Signal)

Source from the content-addressed store, hash-verified

80}
81
82func killContainer(ctx context.Context, container containerd.Container, signal syscall.Signal) (err error) {
83 defer func() {
84 if err != nil {
85 containerutil.UpdateErrorLabel(ctx, container, err)
86 }
87 }()
88 if err := containerutil.UpdateExplicitlyStoppedLabel(ctx, container, true); err != nil {
89 return err
90 }
91 task, err := container.Task(ctx, cio.Load)
92 if err != nil {
93 return err
94 }
95
96 status, err := task.Status(ctx)
97 if err != nil {
98 return err
99 }
100
101 paused := false
102
103 switch status.Status {
104 case containerd.Created, containerd.Stopped:
105 return fmt.Errorf("cannot kill container %s: container is not running", container.ID())
106 case containerd.Paused, containerd.Pausing:
107 paused = true
108 default:
109 }
110
111 if err := task.Kill(ctx, signal); err != nil {
112 return err
113 }
114
115 // Clean up healthcheck systemd units
116 if err := healthcheck.RemoveTransientHealthCheckFiles(ctx, container); err != nil {
117 log.G(ctx).Warnf("failed to clean up healthcheck units for container %s: %s", container.ID(), err)
118 }
119
120 // signal will be sent once resume is finished
121 if paused {
122 if err := task.Resume(ctx); err != nil {
123 log.G(ctx).Warnf("cannot unpause container %s: %s", container.ID(), err)
124 }
125 }
126 return nil
127}
128
129// cleanupNetwork removes cni network setup, specifically the forwards
130func cleanupNetwork(ctx context.Context, container containerd.Container, globalOpts types.GlobalCommandOptions) error {

Callers 1

KillFunction · 0.85

Calls 4

UpdateErrorLabelFunction · 0.92
KillMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…