again

package module
v0.0.0-...-f06587b Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: BSD-2-Clause-Views Imports: 13 Imported by: 11

README

again

graceful restarts with multiple listeners support for Go

Documentation

Index

Constants

View Source
const (
	SIGINT  = syscall.SIGINT
	SIGQUIT = syscall.SIGQUIT
	SIGTERM = syscall.SIGTERM
	SIGUSR2 = syscall.SIGUSR2
)

Don't make the caller import syscall.

Variables

View Source
var OnForkHook func()

Functions

func Child

func Child() bool

Child returns true if this process is managed by again and its a child process.

func Exec

func Exec(a *Again) error

Re-exec this same image without dropping the net.Listener.

func ForkExec

func ForkExec(a *Again) error

Fork and exec this same image without dropping the net.Listener.

func IsErrClosing

func IsErrClosing(err error) bool

IsErrClosing tests whether an error is equivalent to net.errClosing as returned by Accept during a graceful exit.

func Kill

func Kill() error

Kill process specified in the environment with the signal specified in the environment; default to SIGQUIT.

func ListenFrom

func ListenFrom(a *Again, forkHook func()) error

func ListerName

func ListerName(l net.Listener) string

func Wait

func Wait(a *Again) (syscall.Signal, error)

Wait waits for signals

Types

type Again

type Again struct {
	Hooks Hooks
	// contains filtered or unexported fields
}

Again manages services that need graceful restarts

func Listen

func Listen(forkHook func()) (*Again, error)

Listen checks env and constructs a Again instance if this is a child process that was froked by again parent.

forkHook if provided will be called before forking.

func New

func New(hooks ...Hooks) Again

func (Again) Close

func (a Again) Close() error

Close tries to close all service listeners

func (Again) Delete

func (a Again) Delete(name string)

func (*Again) Env

func (a *Again) Env() (m map[string]string, err error)

func (Again) Get

func (a Again) Get(name string) *Service

func (Again) GetListener

func (a Again) GetListener(key string) net.Listener

func (*Again) Listen

func (a *Again) Listen(name string, ls net.Listener) error

Listen creates a new service with the given listener.

func (*Again) Range

func (a *Again) Range(fn func(*Service))

type Hooks

type Hooks struct {
	// OnSIGHUP is the function called when the server receives a SIGHUP
	// signal. The normal use case for SIGHUP is to reload the
	// configuration.
	OnSIGHUP func(*Again) error
	// OnSIGUSR1 is the function called when the server receives a
	// SIGUSR1 signal. The normal use case for SIGUSR1 is to repon the
	// log files.
	OnSIGUSR1 func(*Again) error
	// OnSIGQUIT use this for graceful shutdown
	OnSIGQUIT func(*Again) error
	OnSIGTERM func(*Again) error
}

Hooks callbacks invoked when specific signal is received.

type Service

type Service struct {
	Name       string
	FdName     string
	Descriptor uintptr
	Listener   net.Listener
}

Service is a single service listening on a single net.Listener.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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