Documentation
¶
Overview ¶
Package graceful orchestrates the lifecycle of long-running components. A Group starts every registered component together, waits for a shutdown signal (SIGINT/SIGTERM) or the first failure, then drains everything in reverse registration order within a bounded timeout. With WithUpgrade a SIGHUP performs a zero-downtime binary upgrade via tableflip: listeners created through Listen are inherited by the new process.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group runs components together. Register with Add and Listen, then call Run once; Group is not safe for concurrent registration.
func (*Group) Add ¶
Add registers a component. start runs in a goroutine and may block for the component's whole life (an accept loop) or return nil immediately after spawning its own work (a scheduler): returning a non-nil error shuts the whole group down. stop is called during shutdown, bounded by the group's shutdown timeout, in reverse registration order.
func (*Group) Listen ¶
Listen registers srv to serve on a TCP listener bound to addr. The listener is created by Run — through tableflip under WithUpgrade, so upgraded processes inherit it. http.ErrServerClosed is treated as a clean exit.
type Option ¶
type Option func(*options)
func WithLogger ¶
WithLogger sets the logger for lifecycle events. Default slog.Default().
func WithShutdownTimeout ¶
WithShutdownTimeout bounds the total drain time on shutdown. Default 30s.
func WithUpgrade ¶
func WithUpgrade() Option
WithUpgrade enables zero-downtime binary upgrades on SIGHUP via tableflip. It is a no-op on Windows, where the group falls back to plain listeners.