system

package
v0.0.0-...-16b8bb0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2016 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const BUFFER_SIZE = 10000

Maximum number of bytes kept if log buffer

Variables

View Source
var DEFAULT_PATHS = []string{"/etc/systemd/system/", "/run/systemd/system", "/lib/systemd/system"}

Default paths to search for unit paths - Daemon uses those, if none are specified

View Source
var ErrDepConflict = errors.New("Error stopping conflicting unit")
View Source
var ErrDepFail = errors.New("Dependency failed to start. See unit log for details.")
View Source
var ErrExists = errors.New("Unit already exists")
View Source
var ErrIsDir = errors.New("Is a directory")
View Source
var ErrIsStarting = errors.New("Unit is already starting")
View Source
var ErrNoReload = errors.New("Unit does not support reloading")
View Source
var ErrNotActive = errors.New("Unit is not active")
View Source
var ErrNotDir = errors.New("Is not a directory")
View Source
var ErrNotFound = errors.New("Not found")
View Source
var ErrNotImplemented = errors.New("Not implemented yet")
View Source
var ErrNotLoaded = errors.New("Unit is not loaded.")
View Source
var ErrUnknownType = errors.New("Unknown type")
View Source
var ErrUnmergeable = errors.New("Unmergeable job types")

Functions

func Supported

func Supported(filename string) bool

Supported returns a bool indicating if filename represents a unit type, which is supported by Systemgo

func SupportedSuffix

func SupportedSuffix(suffix string) bool

SupportedSuffix returns a bool indicating if suffix represents a unit type, which is supported by Systemgo

Types

type Daemon

type Daemon struct {
	// System log
	Log *Log
	// contains filtered or unexported fields
}

Daemon supervises instances of Unit

func New

func New() (sys *Daemon)

New returns an instance of a Daemon ready to use

func (*Daemon) Disable

func (sys *Daemon) Disable(names ...string) (err error)

Disable gets names from internal hasmap and calls Disable() on each unit returned

func (*Daemon) Enable

func (sys *Daemon) Enable(names ...string) (err error)

Enable gets names from internal hasmap and calls Enable() on each unit returned

func (*Daemon) Get

func (sys *Daemon) Get(name string) (u *Unit, err error)

Get looks up the unit name in the internal hasmap of loaded units and calls sys.Load(name) if it can not be found. If error is returned, it will be error from sys.Load(name)

func (*Daemon) IsActive

func (sys *Daemon) IsActive(name string) (st unit.Activation, err error)

IsActive returns activation state of the unit held in-memory under specified name. If error is returned, it is going to be ErrNotFound

func (*Daemon) IsEnabled

func (sys *Daemon) IsEnabled(name string) (st unit.Enable, err error)

IsEnabled returns enable state of the unit held in-memory under specified name. If error is returned, it is going to be ErrNotFound

TODO

func (*Daemon) Isolate

func (sys *Daemon) Isolate(names ...string) (err error)

Isolate gets names from internal hashmap, creates a new start transaction, adds a stop job for each unit currently active, but not in the transaction already and runs the transaction

func (*Daemon) Paths

func (sys *Daemon) Paths() (paths []string)

Paths returns paths, which get searched for unit files by sys(first path gets searched first)

func (*Daemon) Reload

func (sys *Daemon) Reload(names ...string) (err error)

Reload gets names from internal hashmap, creates a new reload transaction and runs it

func (*Daemon) Restart

func (sys *Daemon) Restart(names ...string) (err error)

Restart gets names from internal hashmap, creates a new restart transaction and runs it

func (*Daemon) SetPaths

func (sys *Daemon) SetPaths(paths ...string)

SetPaths sets paths, which get searched for unit files by sys(first path gets searched first)

func (*Daemon) Since

func (sys *Daemon) Since() (t time.Time)

Since returns time, when sys was created

func (*Daemon) Start

func (sys *Daemon) Start(names ...string) (err error)

Start gets names from internal hashmap, creates a new start transaction and runs it

func (*Daemon) Status

func (sys *Daemon) Status() (st Status, err error)

Status returns status of the system If error is returned it is going to be an error, returned by the call to ioutil.ReadAll(sys.Log)

func (*Daemon) StatusOf

func (sys *Daemon) StatusOf(name string) (st unit.Status, err error)

StatusOf returns status of the unit held in-memory under specified name. If error is returned, it is going to be ErrNotFound

func (*Daemon) Stop

func (sys *Daemon) Stop(names ...string) (err error)

Stop gets names from internal hashmap, creates a new stop transaction and runs it

func (*Daemon) Supervise

func (sys *Daemon) Supervise(name string, v unit.Interface) (u *Unit, err error)

Supervise creates a *Unit wrapping v and stores it in internal hashmap. If a unit with name specified already exists - nil and ErrExists are returned

func (*Daemon) Unit

func (sys *Daemon) Unit(name string) (u *Unit, err error)

Unit looks up unit name in the internal hasmap and returns the unit created associated with it or nil and ErrNotFound, if it does not exist

func (*Daemon) Units

func (sys *Daemon) Units() (units []*Unit)

Units returns a slice of all units created

type Log

type Log struct {
	*log.Logger
	*bytes.Reader
	// contains filtered or unexported fields
}

Log uses log.Logger to write data to embedded bytes.Buffer Keeps up to 10000 bytes of data in-memory

func NewLog

func NewLog() (l *Log)

NewLog returns a new log

func (*Log) Cap

func (l *Log) Cap() (n int)

func (*Log) Len

func (l *Log) Len() (n int)

func (*Log) Read

func (l *Log) Read(b []byte) (n int, err error)

func (*Log) Write

func (l *Log) Write(b []byte) (n int, err error)

type State

type State int

System state

const (
	Initializing State = iota
	Starting
	Running
	Degraded
	Maintenance
	Stopping
)

type Status

type Status struct {
	// State of the system
	State State `json:"State,string"`

	// Number of queued jobs in-total
	Jobs int `json:"Jobs"`

	// Number of failed units
	Failed int `json:"Failed"`

	// Init time
	Since time.Time `json:"Since"`

	// Log
	Log []byte `json:"Log, omitempty"`
}

System status

func (Status) String

func (s Status) String() (out string)

type Target

type Target struct {
	unit.Definition
	System *Daemon
}

Target unit type is used for grouping units

func (*Target) Active

func (targ *Target) Active() unit.Activation

Active returns activation status of the unit

func (*Target) Define

func (targ *Target) Define(r io.Reader) (err error)

Define attempts to fill the targ definition by parsing r

func (*Target) Sub

func (targ *Target) Sub() string

type Unit

type Unit struct {
	unit.Interface

	// System the Unit came from
	System *Daemon

	// Unit log
	Log *Log
	// contains filtered or unexported fields
}

func NewUnit

func NewUnit(v unit.Interface) (u *Unit)

NewUnit returns an instance of new unit wrapping v

func (*Unit) Active

func (u *Unit) Active() (st unit.Activation)

func (*Unit) Disable

func (u *Unit) Disable() (err error)

Disable removes symlinks(if they exist) created by Enable

func (*Unit) Enable

func (u *Unit) Enable() (err error)

Enable creates symlinks to u definition in dependency directories of each unit dependant on u

func (*Unit) IsActivating

func (u *Unit) IsActivating() bool

func (*Unit) IsActive

func (u *Unit) IsActive() bool

func (*Unit) IsDeactivating

func (u *Unit) IsDeactivating() bool

func (*Unit) IsDead

func (u *Unit) IsDead() bool

func (*Unit) IsLoaded

func (u *Unit) IsLoaded() bool

func (*Unit) IsReloader

func (u *Unit) IsReloader() (ok bool)

IsReloader returns whether u.Interface is capable of reloading

func (*Unit) IsReloading

func (u *Unit) IsReloading() bool

func (*Unit) Loaded

func (u *Unit) Loaded() unit.Load

Loaded returns load state of the unit

func (*Unit) Name

func (u *Unit) Name() string

Name returns the name of the unit(filename of the defintion)

func (*Unit) Path

func (u *Unit) Path() string

Path returns path to the defintion unit was loaded from

func (*Unit) Reload

func (u *Unit) Reload() (err error)

Reload creates a new reload transaction and runs it

func (*Unit) Requires

func (u *Unit) Requires() (names []string)

Requires returns a slice of unit names as found in definition and absolute paths of units symlinked in units '.wants' directory

func (*Unit) Start

func (u *Unit) Start() (err error)

Start creates a new start transaction and runs it

func (*Unit) Status

func (u *Unit) Status() unit.Status

Status returns status of the unit

func (*Unit) Stop

func (u *Unit) Stop() (err error)

Stop creates a new stop transaction and runs it

func (*Unit) Sub

func (u *Unit) Sub() string

func (*Unit) Wants

func (u *Unit) Wants() (names []string)

Wants returns a slice of unit names as found in definition and absolute paths of units symlinked in units '.wants' directory

Jump to

Keyboard shortcuts

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