daemon

package
v0.0.0-...-64a0d4e Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2017 License: BSD-3-Clause Imports: 5 Imported by: 1

Documentation

Overview

Package daemon is a simple service supervisor, currently built around the service interface of the suture project: https://github.com/thejerf/suture

The top level function Run takes a registry and orchestrates the running of a daemon based on suture.Services implemented in the registry. It also has hooks for custom initialize and termination behavior.

Daemon is also a great example of a simple component acting as a micro-framework. It's built around an interface representing the idea of "services". If daemon is not able to satisfy requirements with the use of extension points, you can write your own alternative. As long as it uses the same interface and semantics for services, it would be compatible with components exposing services for this package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoServices is returned when there are no objects in the registry to start as services
	ErrNoServices = errors.New("no services in registry to run")
)

Functions

func Run

func Run(reg *objects.Registry, name string) error

Run takes a registry and registers the daemon.Component, calls Initializers, sets up a parent suture.Service adding any registered suture.Services to it, sets up a goroutine to listen for SIGINT, then calls the blocking Serve on the parent suture.Service. The first error returned by an Initializer or Terminator is returned if any.

Types

type Component

type Component struct {
	Initializers []Initializer    `com:"extpoint"`
	Services     []suture.Service `com:"extpoint"`
	Terminators  []Terminator     `com:"extpoint"`
}

Component is the main package component.

type Initializer

type Initializer interface {
	InitializeDaemon() error
}

Initializer is an extension point interface with a hook for components to initialize before services are started. Returning an error will cancel the start of the daemon services.

type Terminator

type Terminator interface {
	TerminateDaemon() error
}

Terminator is an extension point interface with a hook for components to handle daemon termination via SIGINT signals, which will first Stop all services and then run this hook.

Jump to

Keyboard shortcuts

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