services

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewInfoLogger

func NewInfoLogger() *zap.Logger

NewInfoLogger returns an instance of info-level logger.

func NewLogger

func NewLogger() *zap.Logger

NewLogger returns an instance of logger.

Types

type Config

type Config struct {
	Units []*Unit `json:"units,omitempty"`
	// contains filtered or unexported fields
}

Config is a configuration of Manager.

func NewConfig

func NewConfig() *Config

NewConfig returns an instance of Config.

func (*Config) AddUnit

func (cfg *Config) AddUnit(u *Unit) error

AddUnit adds a unit entry to Config.

func (*Config) Services

func (cfg *Config) Services() ([]*Service, error)

Services validates the config and creates a list of services.

type Manager

type Manager struct {
	Services []*Service `json:"services,omitempty"`
	// contains filtered or unexported fields
}

Manager manages services.

func NewManager

func NewManager(cfg *Config, logger *zap.Logger) (*Manager, error)

NewManager parses config and creates Manager instance.

func (*Manager) Start

func (m *Manager) Start() []*Status

Start starts services.

func (*Manager) Stop

func (m *Manager) Stop() []*Status

Stop stops services.

type Service

type Service struct {
	Seq    int        `json:"seq,omitempty"`
	Unit   *Unit      `json:"unit,omitempty"`
	Status *Status    `json:"status,omitempty"`
	State  *State     `json:"state,omitempty"`
	Kind   WorkerKind `json:"kind,omitempty"`
	// contains filtered or unexported fields
}

Service represents an application instance.

func NewService

func NewService(seq int, unit *Unit, logger *zap.Logger) (*Service, error)

NewService creates Service instance.

func (*Service) Start

func (svc *Service) Start() error

Start starts Service instance.

func (*Service) Stop

func (svc *Service) Stop() error

Stop stops Service instance.

type State

type State struct {
	Current     StateKind `json:"current,omitempty"`
	ServiceName string    `json:"service_name,omitempty"`
	Error       error     `json:"error,omitempty"`
}

State represent the last recorded state of a service.

func NewState

func NewState(name string, kind StateKind) *State

NewState creates State instance.

type StateKind

type StateKind int
const (
	UnknownState StateKind = iota
	PendingState
	RunningState
	StoppedState
	PausedState
	CompletedState
)
const (
	UnknownWorker StateKind = iota
	CommandWorker
	ApplicationWorker
)

func (StateKind) EnumIndex

func (k StateKind) EnumIndex() int

func (StateKind) MarshalJSON

func (k StateKind) MarshalJSON() ([]byte, error)

func (StateKind) String

func (k StateKind) String() string

type Status

type Status struct {
	Current     StatusKind `json:"current,omitempty"`
	ServiceName string     `json:"service_name,omitempty"`
	Error       error      `json:"error,omitempty"`
}

Status represent the last recorded status of a service.

func NewStatus

func NewStatus(name string, kind StatusKind) *Status

NewStatus creates Status instance.

type StatusKind

type StatusKind int
const (
	UnknownStatus StatusKind = iota
	PendingStatus
	FailureStatus
	SuccessStatus
)

func (StatusKind) EnumIndex

func (k StatusKind) EnumIndex() int

func (StatusKind) MarshalJSON

func (k StatusKind) MarshalJSON() ([]byte, error)

func (StatusKind) String

func (k StatusKind) String() string

type Unit

type Unit struct {
	// The order of the unit in Config.
	Seq int `json:"seq,omitempty"`
	// The alias for the Unit.
	Name string `json:"name,omitempty"`
	// The description of the Unit.
	Description string `json:"description,omitempty"`
	// The type of the Unit: app, command.
	Kind string `json:"kind,omitempty"`
	// The command to execute.
	Command string `json:"cmd,omitempty"`
	// The executed command arguments.
	Arguments []string `json:"args,omitempty"`
	// The directory the command starts in.
	WorkDirectory string `json:"workdir,omitempty"`
	// The higher the Priority the sooner this unit activates. The Manager
	// activates units with the same Priority in alphabetical order.
	Priority uint64 `json:"priority,omitempty"`
	// If set to true, the unit will not be started or stopped.
	Noop bool `json:"noop,omitempty"`
	// Not implemented.
	Wants []string `json:"wants,omitempty"`
	// Not implemented.
	Requires []string `json:"requires,omitempty"`
	// The names of the Units that need to start after this one.
	Before []string `json:"before,omitempty"`
	// The names of the Units that need to start prior to this one.
	After []string `json:"after,omitempty"`
	// The path to standard output file.
	StdOutFilePath string `json:"std_out_file_path,omitempty"`
	// The path to err output file.
	StdErrFilePath string `json:"std_err_file_path,omitempty"`
}

Unit is a configuration for a command or app.

func NewUnit

func NewUnit(kind, name string) (*Unit, error)

NewUnit returns an instance of Unit.

type WorkerKind

type WorkerKind int

func (WorkerKind) EnumIndex

func (k WorkerKind) EnumIndex() int

func (WorkerKind) MarshalJSON

func (k WorkerKind) MarshalJSON() ([]byte, error)

func (WorkerKind) String

func (k WorkerKind) String() string

Jump to

Keyboard shortcuts

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