graceful

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 11 Imported by: 2

README

Package graceful v1.2.0

Default settings

SIGINT and SIGTERM are stopping the application SIGHUB is gracefully restarting it.

Graceful shutdown:

  • 1 minute to finish requests
  • Then connections cut

Graceful restart:

  • Socket file descriptor given to fork/exec child
  • 30 minutes to finish requests for old process (can switch to shutdown with a SIGINT/SIGTERM on this process)

Usage

graceful.NewService()

Configuration with options

s := graceful.NewService(
	graceful.WithWaitDuration(30 * time.Second),
	graceful.WithReloadWaitDuration(time.Hour),
	graceful.WithPIDFile("/var/run/service.pid"),
)

err := s.ListenAndServe(ctx, "tcp", ":9000", handler)

Configuration for multiple servers

s := graceful.NewService(
	graceful.WithWaitDuration(30 * time.Second),
	graceful.WithReloadWaitDuration(time.Hour),
	graceful.WithPIDFile("/var/run/service.pid"),
	graceful.WithNumServers(2),
)

err := s.ListenAndServe(ctx, "tcp", ":9000", handler)
err := s.ListenAndServe(ctx, "tcp", ":9001", handler2)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Service)

func WithNumServers added in v1.2.0

func WithNumServers(n int) Option

func WithPIDFile

func WithPIDFile(path string) Option

func WithReloadWaitDuration

func WithReloadWaitDuration(d time.Duration) Option

func WithWaitDuration

func WithWaitDuration(d time.Duration) Option

type Service added in v1.1.2

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

func NewService

func NewService(opts ...Option) *Service

func (*Service) DecConnCount added in v1.1.2

func (s *Service) DecConnCount(ctx context.Context)

DecConnCount is the same as IncConnCount, but you need to call it when the hijacked connection is stopped

func (*Service) IncConnCount added in v1.1.2

func (s *Service) IncConnCount(ctx context.Context)

IncConnCount has to be used when connections are hijacked because in this case http.Server doesn't track these connection anymore, but you may not want to cut them abrutely.

func (*Service) ListenAndServe added in v1.1.2

func (s *Service) ListenAndServe(ctx context.Context, proto string, addr string, handler http.Handler) error

func (*Service) ListenAndServeTLS added in v1.1.2

func (s *Service) ListenAndServeTLS(ctx context.Context, proto string, addr string, handler http.Handler, tlsConfig *tls.Config) error

Jump to

Keyboard shortcuts

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