graceful

package
v3.1.52 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetListener = DefaultGetListener

GetListener returns a net listener This determines the implementation of net.Listener which the server will use, so that downstreams could provide their own Listener, such as with a hidden service or a p2p network

Functions

func DefaultGetListener

func DefaultGetListener(network, address string) (net.Listener, error)

DefaultGetListener obtains a listener for the stream-oriented local network address: "tcp", "tcp4", "tcp6", "unix" or "unixpacket".

func GetListenerTCP

func GetListenerTCP(network string, address *net.TCPAddr) (*net.TCPListener, error)

GetListenerTCP announces on the local network address. The network must be: "tcp", "tcp4" or "tcp6". It returns a provided net.Listener for the matching network and address, or creates a new one using net.ListenTCP.

func GetListenerUnix

func GetListenerUnix(network string, address *net.UnixAddr) (*net.UnixListener, error)

GetListenerUnix announces on the local network address. The network must be: "unix" or "unixpacket". It returns a provided net.Listener for the matching network and address, or creates a new one using net.ListenUnix.

func HTTPListenAndServe

func HTTPListenAndServe(network, address, name string, handler http.Handler, useProxyProtocol bool) error

HTTPListenAndServe listens on the provided network address and then calls Serve to handle requests on incoming connections.

func HTTPListenAndServeTLSConfig

func HTTPListenAndServeTLSConfig(network, address, name string, tlsConfig *tls.Config, handler http.Handler, useProxyProtocol, proxyProtocolTLSBridging bool) error

HTTPListenAndServeTLSConfig listens on the provided network address and then calls Serve to handle requests on incoming connections.

func InitManager

func InitManager(ctx context.Context)

InitManager creates the graceful manager in the provided context

func KillParent

func KillParent()

KillParent sends the kill signal to the parent process if we are a child

func RestartProcess

func RestartProcess() (int, error)

RestartProcess starts a new process passing it the active listeners. It doesn't fork, but starts a new process using the same environment and arguments as when it was originally started. This allows for a newly deployed binary to be started. It returns the pid of the newly started process when successful.

Types

type Manager

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

Manager manages the graceful shutdown process

func GetManager

func GetManager() *Manager

GetManager returns the Manager

func (*Manager) Deadline

func (g *Manager) Deadline() (deadline time.Time, ok bool)

Deadline returns nil as there is no fixed Deadline for the manager, it allows the manager to be viewed as a context.Context

func (*Manager) DoGracefulRestart

func (g *Manager) DoGracefulRestart()

DoGracefulRestart causes a graceful restart

func (*Manager) DoGracefulShutdown

func (g *Manager) DoGracefulShutdown()

DoGracefulShutdown causes a graceful shutdown

func (*Manager) DoImmediateHammer

func (g *Manager) DoImmediateHammer()

DoImmediateHammer causes an immediate hammer

func (*Manager) Done

func (g *Manager) Done() <-chan struct{}

Done allows the manager to be viewed as a context.Context, it returns a channel that is closed when the server is finished terminating

func (*Manager) Err

func (g *Manager) Err() error

Err allows the manager to be viewed as a context.Context done at Terminate

func (*Manager) HammerContext

func (g *Manager) HammerContext() context.Context

HammerContext returns a context.Context that is Done at hammer Callers using this context should ensure that they are registered as a running server in order that they are waited for.

func (*Manager) InformCleanup

func (g *Manager) InformCleanup()

InformCleanup tells the cleanup wait group that we have either taken a listener or will not be taking a listener. At the moment the total number of servers (numberOfServersToCreate) are pre-defined as a const before global init, so this function MUST be called if a server is not used.

func (*Manager) IsChild

func (g *Manager) IsChild() bool

IsChild returns if the current process is a child of previous Gitea process

func (*Manager) IsHammer

func (g *Manager) IsHammer() <-chan struct{}

IsHammer returns a channel which will be closed at hammer. Servers running within the running server wait group should respond to IsHammer if not shutdown already

func (*Manager) IsShutdown

func (g *Manager) IsShutdown() <-chan struct{}

IsShutdown returns a channel which will be closed at shutdown. The order of closure is shutdown, hammer (potentially), terminate

func (*Manager) RegisterServer

func (g *Manager) RegisterServer()

RegisterServer registers the running of a listening server, in the case of unix this means that the parent process can now die. Any call to RegisterServer must be matched by a call to ServerDone

func (*Manager) RunAtShutdown

func (g *Manager) RunAtShutdown(ctx context.Context, shutdown func())

RunAtShutdown creates a go-routine to run the provided function at shutdown

func (*Manager) RunAtTerminate

func (g *Manager) RunAtTerminate(terminate func())

RunAtTerminate adds to the terminate wait group and creates a go-routine to run the provided function at termination

func (*Manager) RunWithCancel

func (g *Manager) RunWithCancel(rc RunCanceler)

RunWithCancel helps to run a function with a custom context, the Cancel function will be called at shutdown The Cancel function should stop the Run function in predictable time.

func (*Manager) RunWithShutdownContext

func (g *Manager) RunWithShutdownContext(run func(context.