serverd

package
v0.0.0-...-a54a33a Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: AGPL-3.0 Imports: 9 Imported by: 5

Documentation

Overview

Package serverd provides a component to create server-type applications, helping to manage the life cycle of services and operating system signals.

This package is a work in progress and makes no API stability promises.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager manages the services.

func New

func New(name string, opt ...Option) *Manager

New creates a new manager.

func (*Manager) Ping

func (m *Manager) Ping() error

Ping will ping all registered services.

func (*Manager) Register

func (m *Manager) Register(svc Service) error

Register resgisters a new service in the manager. Services cannot be registered if it has already been started.

func (*Manager) Reload

func (m *Manager) Reload() error

Reload will reload all registered services.

func (*Manager) Run

func (m *Manager) Run() error

Run will initialize all services, install the operating system's signal handlers and block waiting for the shutdown signal. When this signal arrives, it will turn off all registered services.

func (*Manager) Shutdown

func (m *Manager) Shutdown()

Shutdown will stop all services in the opposite order to which they were registered. It will try to execute the "shutdown" function and, if it is turned off in a given time, it will execute the "stop" function of the service.

func (*Manager) Start

func (m *Manager) Start() error

Start starts managed services in the same order they were registered. If there is an error then it will stop.

type Option

type Option func(*options)

Option is used for component configuration.

func SetLogger

func SetLogger(l yalogi.Logger) Option

SetLogger option allows set a custom logger.

func ShutdownTimeout

func ShutdownTimeout(d time.Duration) Option

ShutdownTimeout option sets timeout for shutdowns.

type PingFn

type PingFn func() error

PingFn sets definition for ping functions.

type ReloadFn

type ReloadFn func() error

ReloadFn sets definition for reload functions.

type Service

type Service struct {
	Name     string
	Start    StartupFn
	Shutdown ShutdownFn
	Stop     StopFn
	Reload   ReloadFn
	Ping     PingFn
}

Service defines data struct for services.

type ShutdownFn

type ShutdownFn func()

ShutdownFn sets definition for gracely shutdown functions.

type StartupFn

type StartupFn func() error

StartupFn sets definition for startup functions.

type StopFn

type StopFn func()

StopFn sets definition for stop functions (force).

Jump to

Keyboard shortcuts

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