|
func killContainer(ctx context.Context, container containerd.Container, signal syscall.Signal) (err error) { |
|
defer func() { |
|
if err != nil { |
|
containerutil.UpdateErrorLabel(ctx, container, err) |
|
} |
|
}() |
|
if err := containerutil.UpdateExplicitlyStoppedLabel(ctx, container, true); err != nil { |
|
return err |
|
} |
|
task, err := container.Task(ctx, cio.Load) |
|
if err != nil { |
|
return err |
|
} |
|
|
|
status, err := task.Status(ctx) |
|
if err != nil { |
|
return err |
|
} |
|
|
|
paused := false |
|
|
|
switch status.Status { |
|
case containerd.Created, containerd.Stopped: |
|
return fmt.Errorf("cannot kill container %s: container is not running", container.ID()) |
|
case containerd.Paused, containerd.Pausing: |
|
paused = true |
|
default: |
|
} |
|
|
|
if err := task.Kill(ctx, signal); err != nil { |
|
return err |
|
} |
|
|
|
// Clean up healthcheck systemd units |
|
if err := healthcheck.RemoveTransientHealthCheckFiles(ctx, container); err != nil { |
|
log.G(ctx).Warnf("failed to clean up healthcheck units for container %s: %s", container.ID(), err) |
|
} |
|
|
|
// signal will be sent once resume is finished |
|
if paused { |
|
if err := task.Resume(ctx); err != nil { |
|
log.G(ctx).Warnf("cannot unpause container %s: %s", container.ID(), err) |
|
} |
|
} |
|
return nil |
|
} |
nerdctl kill can be used for non-stop signals such as HUP, so it shouldn't unconditionally set containerd.io/restart.explicitly-stopped label
nerdctl/pkg/cmd/container/kill.go
Lines 82 to 127 in 592c011
nerdctl killcan be used for non-stop signals such asHUP, so it shouldn't unconditionally setcontainerd.io/restart.explicitly-stoppedlabel