trap/trap.go

moby · daemon/command/trap/trap.go · go · Apache-2.0
infra, tag:knn-classified

Sets up signal handling to cleanly shutdown a Unix command-line tool.

// Source: https://github.com/moby/moby | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
package trap

import (
	"context"
	"os"
	"os/signal"
	"syscall"

	"github.com/containerd/log"
)

const (
	// Immediately terminate the process when this many SIGINT or SIGTERM
	// signals are received.
	forceQuitCount = 3
)

// Trap sets up a simplified signal "trap", appropriate for common
// behavior expected from a vanilla unix command-line tool in general
// (and the Docker engine in particular).
//
// The first time a SIGINT or SIGTERM signal is received, `cleanup` is called in
// a new goroutine.
//
// If SIGINT or SIGTERM are received 3 times, the process is terminated
// immediately wit

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key