zinit

package
v0.6.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package zinit exposes function to interat with zinit service life cyle management

Index

Constants

View Source
const (
	// ServiceStateUnknown is return when we cannot determine the status of a service
	ServiceStateUnknown PossibleState = "unknown"
	// ServiceStateRunning is return when we a service process is running and healthy
	ServiceStateRunning = "running"
	// ServiceStateBlocked  is returned if the service can't start because of an unsatisfied dependency
	ServiceStateBlocked = "blocked"
	// ServiceStateSpawned service has started, but zinit is not sure about its status yet.
	// this is usually a short-lived status, unless a test command is provided. In that case
	// the spawned state will only go to success if the test pass
	ServiceStateSpawned = "spawned"
	// ServiceStateSuccess is return when a one shot service exited without errors
	ServiceStateSuccess = "success"
	// ServiceStateError is return when we a service exit with an error (exit code != 0)
	ServiceStateError = "error"
	//ServiceStateFailure is set of zinit can not spawn a service in the first place
	//due to a missing executable for example. Unlike `error` which is returned if the
	//service itself exits with an error.
	ServiceStateFailure = "failure"
)

Variables

View Source
var (
	SIGABRT   = Signal("SIGABRT")
	SIGALRM   = Signal("SIGALRM")
	SIGBUS    = Signal("SIGBUS")
	SIGCHLD   = Signal("SIGCHLD")
	SIGCLD    = Signal("SIGCLD")
	SIGCONT   = Signal("SIGCONT")
	SIGFPE    = Signal("SIGFPE")
	SIGHUP    = Signal("SIGHUP")
	SIGILL    = Signal("SIGILL")
	SIGINT    = Signal("SIGINT")
	SIGIO     = Signal("SIGIO")
	SIGIOT    = Signal("SIGIOT")
	SIGKILL   = Signal("SIGKILL")
	SIGPIPE   = Signal("SIGPIPE")
	SIGPOLL   = Signal("SIGPOLL")
	SIGPROF   = Signal("SIGPROF")
	SIGPWR    = Signal("SIGPWR")
	SIGQUIT   = Signal("SIGQUIT")
	SIGSEGV   = Signal("SIGSEGV")
	SIGSTKFLT = Signal("SIGSTKFLT")
	SIGSTOP   = Signal("SIGSTOP")
	SIGSYS    = Signal("SIGSYS")
	SIGTERM   = Signal("SIGTERM")
	SIGTRAP   = Signal("SIGTRAP")
	SIGTSTP   = Signal("SIGTSTP")
	SIGTTIN   = Signal("SIGTTIN")
	SIGTTOU   = Signal("SIGTTOU")
	SIGUNUSED = Signal("SIGUNUSED")
	SIGURG    = Signal("SIGURG")
	SIGUSR1   = Signal("SIGUSR1")
	SIGUSR2   = Signal("SIGUSR2")
	SIGVTALRM = Signal("SIGVTALRM")
	SIGWINCH  = Signal("SIGWINCH")
	SIGXCPU   = Signal("SIGXCPU")
	SIGXFSZ   = Signal("SIGXFSZ")
)

List of supported signal

View Source
var (

	// ErrUnknownService is an error that is returned when a service is unknown to zinit
	ErrUnknownService = errors.New("unknown service")
)

Functions

func AddService

func AddService(name string, service InitService) error

AddService write the service into a file in the expected location for Zinit you usually want to call Monitor(name) after adding a service

func RemoveService

func RemoveService(name string) error

RemoveService delete the service file from the filesystem make sure the service has been stopped and forgot before deleting it

Types

type Client

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

Client is a client for zinit action it talks to zinit directly over its unis socket

func New

func New(socket string) (*Client, error)

New create a new Zinit client

func (*Client) Close

func (c *Client) Close() error

Close closes the socket connection

func (*Client) Forget

func (c *Client) Forget(service string) error

Forget forgets a service. you can only forget a stopped service

func (*Client) Kill

func (c *Client) Kill(service string, sig Signal) error

Kill sends a signal to a running service. sig must be a valid signal (SIGINT, SIGKILL,...)

func (*Client) List

func (c *Client) List() (map[string]ServiceState, error)

List returns all the service monitored and their status

func (*Client) Monitor

func (c *Client) Monitor(service string) error

Monitor starts monitoring a service

func (*Client) Start

func (c *Client) Start(service string) error

Start start service. has no effect if the service is already running

func (*Client) StartWait

func (c *Client) StartWait(timeout time.Duration, service string) error

StartWait starts a service and wait until its running, or until the timeout (seconds) pass. If timedout, the method returns an error if the service is not running timout of 0 means no wait. (similar to Stop) timout is a min of 1 second

func (*Client) Status

func (c *Client) Status(service string) (ServiceStatus, error)

Status returns the status of a service

func (*Client) Stop

func (c *Client) Stop(service string) error

Stop stops a service

func (*Client) StopWait

func (c *Client) StopWait(timeout time.Duration, service string) error

StopWait stops a service and wait until it exits, or until the timeout (seconds) pass. If timedout, the service is killed with -9. timout of 0 means no wait. (similar to Stop) timout is a min of 1 second

type InitService

type InitService struct {
	Exec    string   `yaml:"exec,omitempty"`
	Oneshot bool     `yaml:"oneshot,omitempty"`
	Test    string   `yaml:"test,omitempty"`
	After   []string `yaml:"after,omitempty"`
	Log     LogType  `yaml:"log,omitempty"`
}

InitService represent a Zinit service file

type LogType

type LogType string

LogType is an enum type

const (
	StdoutLogType LogType = "stdout"
	RingLogType   LogType = "ring"
)

All the type of logging supported by zinit

func (*LogType) UnmarshalYAML

func (s *LogType) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface

type PossibleState

type PossibleState string

PossibleState represents the state of a service managed by zinit

type ServiceState

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

ServiceState describes the service state

func (*ServiceState) Exited

func (s *ServiceState) Exited() bool

Exited is true if the service state in a (stopped) state

func (*ServiceState) Is

func (s *ServiceState) Is(state PossibleState) bool

Is checks if service state is equal to a possible state

func (*ServiceState) MarshalYAML

func (s *ServiceState) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Unmarshaler interface

func (*ServiceState) String

func (s *ServiceState) String() string

func (*ServiceState) UnmarshalYAML

func (s *ServiceState) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface

type ServiceStatus

type ServiceStatus struct {
	Name   string
	Pid    int
	State  ServiceState
	Target ServiceTarget
	// Deps is the list of dependent services
	// all dependencies needs to be running before a service
	// can starts
	Deps map[string]string
}

ServiceStatus represent the status of a service

type ServiceTarget

type ServiceTarget string

ServiceTarget represents the desired state of a service

const (
	// ServiceTargetUp means the service has been asked to start
	ServiceTargetUp ServiceTarget = "up"
	// ServiceTargetDown means the service has been asked to stop
	ServiceTargetDown = "down"
)

func (*ServiceTarget) UnmarshalYAML

func (s *ServiceTarget) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface

type Signal

type Signal string

Signal is a type that maps linux signal to a string it is used by the Kill method

Jump to

Keyboard shortcuts

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