Documentation
¶
Overview ¶
Package overseer implements daemonizable self-upgrading binaries in Go (golang).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( //DisabledState is a placeholder state for when //overseer is disabled and the program function //is run manually. DisabledState = State{Enabled: false} )
Functions ¶
func ForceNextRestart ¶ added in v1.5.0
func ForceNextRestart()
ForceNextRestart marks the next restart attempt — typically the one following the next successful fetch — to proceed even if Config.ShouldRestart returns false. The mark is consumed when a restart fires or a new worker is forked (any fork runs the current on-disk binary, satisfying the request). Valid in the master process; no-op in the worker.
func IsSupported ¶
func IsSupported() bool
IsSupported returns whether overseer is supported on the current OS.
func Restart ¶
func Restart()
Restart programmatically triggers a graceful restart. If NoRestart is enabled, then this will essentially be a graceful shutdown.
func Run ¶
func Run(c Config)
Run executes overseer, if an error is encountered, overseer fallsback to running the program directly (unless Required is set).
func SanityCheck ¶
func SanityCheck()
SanityCheck manually runs the check to ensure this binary is compatible with overseer. This tries to ensure that a restart is never performed against a bad binary, as it would require manual intervention to rectify. This is automatically done on overseer.Run() though it can be manually run prior whenever necessary.
Types ¶
type Config ¶
type Config struct {
//Required will prevent overseer from fallback to running
//running the program in the main process on failure.
Required bool
//Program's main function
Program func(state State)
//Program's zero-downtime socket listening address (set this or Addresses)
Address string
//Program's zero-downtime socket listening addresses (set this or Address)
Addresses []string
//RestartSignal will manually trigger a graceful restart. Defaults to SIGUSR2.
RestartSignal os.Signal
//TerminateTimeout controls how long overseer should
//wait for the program to terminate itself. After this
//timeout, overseer will issue a SIGKILL.
TerminateTimeout time.Duration
//MinFetchInterval defines the smallest duration between Fetch()s.
//This helps to prevent unwieldy fetch.Interfaces from hogging
//too many resources. Defaults to 1 second.
MinFetchInterval time.Duration
//PreUpgrade runs after a binary has been retrieved, user defined checks
//can be run here and returning an error will cancel the upgrade.
PreUpgrade func(tempBinaryPath string) error
//Debug enables all [overseer] logs.
Debug bool
//NoWarn disables info and warning [overseer] logs.
NoWarn bool
//NoRestart disables all restarts, this option essentially converts
//the RestartSignal into a "ShutdownSignal".
NoRestart bool
//NoRestartAfterFetch disables automatic restarts after each upgrade.
//Though manual restarts using the RestartSignal can still be performed.
NoRestartAfterFetch bool
//Fetcher will be used to fetch binaries.
Fetcher fetcher.Interface
//ShouldRestart, when non-nil, is consulted after a new binary has been
//fetched and swapped but before the graceful restart is triggered. If
//it returns false, the restart is deferred and re-checked on each
//subsequent fetch loop iteration until it returns true. Manual restarts
//via overseer.Restart() bypass this check.
ShouldRestart func() bool
//OnPanic, when non-nil, is invoked after the worker process exits if a
//Go panic/runtime crash is detected in its stderr. The snapshot is
//parsed by panicparse and contains the crashing goroutines. The
//callback is awaited before the master exits, bounded by
//TerminateTimeout so a slow or buggy callback cannot stall shutdown.
OnPanic func(*opanic.Snapshot)
//StderrTailSize is the number of bytes of worker stderr retained in
//memory for panic detection. Only used when OnPanic is set. Defaults
//to 256 KiB.
StderrTailSize int
//WaitDelay bounds how long cmd.Wait blocks on the worker's stderr/stdout
//pipes after the process has exited. If a worker subprocess inherits the
//worker's pipe fd (e.g. via cmd.Stderr = os.Stderr where the worker's
//os.Stderr is itself the master→worker pipe) and outlives the worker,
//the pipe never EOFs and cmd.Wait hangs forever — blocking the master
//from spawning the next worker. Defaults to TerminateTimeout.
WaitDelay time.Duration
}
Config defines overseer's run-time configuration
type Info ¶ added in v1.5.0
type Info struct {
//IsMaster reports whether this snapshot came from a master process.
//It is false in the worker and before Run.
IsMaster bool
//UpgradeStaged reports that the on-disk binary differs from the binary
//the current worker was forked from — an upgrade has been fetched and
//swapped into place but no restart has delivered it yet.
UpgradeStaged bool
//RestartPending reports that an automatic restart was deferred by
//Config.ShouldRestart and is being retried on each fetch loop iteration.
RestartPending bool
//ForceRequested reports that ForceNextRestart was called and the mark
//has not yet been consumed by a restart.
ForceRequested bool
//WorkerForks counts how many times the master has forked a worker.
WorkerForks int
}
Info is a point-in-time snapshot of the master process's upgrade and restart state, retrieved with MasterInfo.
func MasterInfo ¶ added in v1.5.0
func MasterInfo() Info
MasterInfo returns a snapshot of the master's upgrade and restart state. Valid in the master process; in the worker (or before Run) it returns a zero Info with IsMaster=false.
type State ¶
type State struct {
//whether overseer is running enabled. When enabled,
//this program will be running in a child process and
//overseer will perform rolling upgrades.
Enabled bool
//ID is a SHA-1 hash of the current running binary
ID string
//StartedAt records the start time of the program
StartedAt time.Time
//Listener is the first net.Listener in Listeners
Listener net.Listener
//Listeners are the set of acquired sockets by the master
//process. These are all passed into this program in the
//same order they are specified in Config.Addresses.
Listeners []net.Listener
//Program's first listening address
Address string
//Program's listening addresses
Addresses []string
//GracefulShutdown will be filled when its time to perform
//a graceful shutdown.
GracefulShutdown chan bool
//Path of the binary currently being executed
BinPath string
}
State contains the current run-time state of overseer
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package opanic detects Go panics and runtime crashes from a worker process's stderr and parses them into a structured goroutine snapshot via github.com/maruel/panicparse.
|
Package opanic detects Go panics and runtime crashes from a worker process's stderr and parses them into a structured goroutine snapshot via github.com/maruel/panicparse. |