shutdown

package
v6.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ForcedExitCode is the exit status after a second SIGINT/SIGTERM aborts a
	// graceful teardown that has not finished. Distinct from the generic error
	// status (1) so operators can tell a forced abort from a plain error.
	ForcedExitCode = 2
)

Exit statuses surfaced by the run command (see cmd/stroppy/commands/root.go).

Variables

This section is empty.

Functions

func ExitCodeFor

func ExitCodeFor(sig os.Signal) int

ExitCodeFor returns the shell-convention exit status (128 + signal number) for a graceful cancellation triggered by sig: 130 for SIGINT, 143 for SIGTERM. Returns 1 when sig is not a recognizable signal.

func NotifyContext

func NotifyContext(parent context.Context, force func(int)) (
	ctx context.Context, stop func(), exitStatus func() int,
)

NotifyContext returns a context canceled by the first SIGINT/SIGTERM, a stop func, and an exitStatus func reporting the graceful-shutdown exit code derived from that first signal, or 1 before any signal. A second signal after cancellation invokes force(ForcedExitCode) as a bounded escape hatch for a hung teardown; force defaults to os.Exit.

Call stop exactly once when the command is done. It releases the OS handler, drops any already-delivered-but-unconsumed signal, and cancels ctx so no handler goroutine outlives the command.

func Register

func Register(toStop ...StopInterface)

Register registers the provided stoppers.

Variadic parameter of type StopInterface.

func RegisterFn

func RegisterFn(toStop ...func())

RegisterFn registers the provided functions as stoppers.

The variadic parameter `toStop` is a slice of functions that will be registered as stoppers. Each function in `toStop` will be converted to a `StopFn` and registered with the global shutdown manager.

func Stop

func Stop()

Stop stops the global shutdown manager.

This function does not take any parameters. It does not return any values.

func Wait

func Wait(ch chan struct{})

Wait waits for a signal on the given channel before stopping the global shutdown manager.

Parameters: - ch: The channel to wait on for a signal.

func WaitSignal

func WaitSignal(ch chan os.Signal)

WaitSignal waits for a signal on the given channel before stopping the global shutdown manager.

Parameters: - ch: The channel to wait on for a signal.

Types

type StopFn

type StopFn func()

func (StopFn) Stop

func (s StopFn) Stop()

Stop is a method of the StopFn type that executes the underlying function.

type StopInterface

type StopInterface interface {
	Stop()
}

type Stopper

type Stopper struct {
	// contains filtered or unexported fields
}

func Global

func Global() *Stopper

Global returns the global shutdown manager.

It returns a pointer to a Stopper object.

func New

func New() *Stopper

New creates a new instance of the Stopper struct.

It returns a pointer to the newly created Stopper struct.

func (*Stopper) Register

func (s *Stopper) Register(toStop ...StopInterface)

func (*Stopper) Stop

func (s *Stopper) Stop()

Stop stops all registered stop functions.

It iterates over the stops slice and calls the Stop method on each stop function. This function does not take any parameters. It does not return anything.

func (*Stopper) Wait

func (s *Stopper) Wait(ch chan struct{})

Wait waits for a signal on the given channel and then stops the Stopper.

Parameters: - ch: a channel of struct{} type to receive the signal from.

Return type: None.

func (*Stopper) WaitSignal

func (s *Stopper) WaitSignal(ch chan os.Signal)

WaitSignal waits for a signal on the given channel and then stops the Stopper.

Parameters: - ch: a channel of os.Signal type to receive the signal from.

Return type: None.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL