servicestate

package
v0.0.0-...-9e584df Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrQuotaNotFound = errors.New("quota not found")

Functions

func AllQuotas

func AllQuotas(st *state.State) (map[string]*quota.Group, error)

AllQuotas returns all currently tracked quota groups in the state. They are validated for consistency using ResolveCrossReferences before being returned.

func CheckQuotaChangeConflictMany

func CheckQuotaChangeConflictMany(st *state.State, quotaNames []string) error

CheckQuotaChangeConflictMany ensures that for the given quota groups no other changes that alters them (like create, update, remove) are in progress. If a conflict is detected an error is returned.

func Control

func Control(st *state.State, appInfos []*snap.AppInfo, inst *Instruction, flags *Flags, context *hookstate.Context) ([]*state.TaskSet, error)

Control creates a taskset for starting/stopping/restarting services via systemctl. The appInfos and inst define the services and the command to execute. Context is used to determine change conflicts - we will not conflict with tasks from same change as that of context's.

func CreateQuota

func CreateQuota(st *state.State, name string, parentName string, snaps []string, memoryLimit quantity.Size) (*state.TaskSet, error)

CreateQuota attempts to create the specified quota group with the specified snaps in it. TODO: should this use something like QuotaGroupUpdate with fewer fields?

func EnsureSnapAbsentFromQuota

func EnsureSnapAbsentFromQuota(st *state.State, snap string) error

EnsureSnapAbsentFromQuota ensures that the specified snap is not present in any quota group, usually in preparation for removing that snap from the system to keep the quota group itself consistent. This function is idempotent, since if it was interrupted after unlocking the state inside ensureSnapServicesForGroup it will not re-execute since the specified snap will not be present inside the group reference in the state.

func GetQuota

func GetQuota(st *state.State, name string) (*quota.Group, error)

GetQuota returns an individual quota group by name.

func MockEnsuredSnapServices

func MockEnsuredSnapServices(mgr *ServiceManager, ensured bool) (restore func())

func MockSystemdVersion

func MockSystemdVersion(vers int) (restore func())

MockSystemdVersion mocks the systemd version to the given version. This is only available for unit tests and will panic when run in production.

func RemoveQuota

func RemoveQuota(st *state.State, name string) (*state.TaskSet, error)

RemoveQuota deletes the specific quota group. Any snaps currently in the quota will no longer be in any quota group, even if the quota group being removed is a sub-group. TODO: currently this only supports removing leaf sub-group groups, it doesn't support removing parent quotas, but probably it makes sense to allow that too

func SnapServiceOptions

func SnapServiceOptions(st *state.State, instanceName string, quotaGroups map[string]*quota.Group) (opts *wrappers.SnapServiceOptions, err error)

SnapServiceOptions computes the options to configure services for the given snap. This function might not check for the existence of instanceName. It also takes as argument a map of all quota groups as an optimization, the map if non-nil is used in place of checking state for whether or not the specified snap is in a quota group or not. If nil, state is consulted directly instead.

func UpdateQuota

func UpdateQuota(st *state.State, name string, updateOpts QuotaGroupUpdate) (*state.TaskSet, error)

UpdateQuota updates the quota as per the options. TODO: this should support more kinds of updates such as moving groups between parents, removing sub-groups from their parents, and removing snaps from the group.

Types

type Flags

type Flags struct {
	// CreateExecCommandTasks tells Control method to create exec-command tasks
	// (alongside service-control tasks) for compatibility with old snapd.
	CreateExecCommandTasks bool
}

Flags carries extra flags for Control

type Instruction

type Instruction struct {
	Action string   `json:"action"`
	Names  []string `json:"names"`
	client.StartOptions
	client.StopOptions
	client.RestartOptions
}

type QuotaChangeConflictError

type QuotaChangeConflictError struct {
	Quota      string
	ChangeKind string
	// a Message is optional, otherwise one is composed from the other information
	Message string
}

QuotaChangeConflictError represents an error because of quota group conflicts between changes.

func (*QuotaChangeConflictError) Error

func (e *QuotaChangeConflictError) Error() string

type QuotaControlAction

type QuotaControlAction struct {
	// QuotaName is the name of the quota group being controlled.
	QuotaName string `json:"quota-name"`

	// Action is the action being taken on the quota group. It can be either
	// "create", "update", or "remove".
	Action string `json:"action"`

	// AddSnaps is the set of snaps to add to the quota group, valid for either
	// the "update" or the "create" actions.
	AddSnaps []string `json:"snaps"`

	// MemoryLimit is the memory limit for the quota group being controlled,
	// either the initial limit the group is created with for the "create"
	// action, or if non-zero for the "update" the memory limit, then the new
	// value to be set.
	MemoryLimit quantity.Size

	// ParentName is the name of the parent for the quota group if it is being
	// created. Eventually this could be used with the "update" action to
	// support moving quota groups from one parent to another, but that is
	// currently not supported.
	ParentName string
}

QuotaControlAction is the serialized representation of a quota group modification that lives in a task.

type QuotaGroupUpdate

type QuotaGroupUpdate struct {
	// AddSnaps is the set of snaps to add to the quota group. These are
	// instance names of snaps, and are appended to the existing snaps in
	// the quota group
	AddSnaps []string

	// NewMemoryLimit is the new memory limit to be used for the quota group. If
	// zero, then the quota group's memory limit is not changed.
	NewMemoryLimit quantity.Size
}

QuotaGroupUpdate reflects all of the modifications that can be performed on a quota group in one operation.

type ServiceAction

type ServiceAction struct {
	SnapName       string   `json:"snap-name"`
	Action         string   `json:"action"`
	ActionModifier string   `json:"action-modifier,omitempty"`
	Services       []string `json:"services,omitempty"`
	// ExplicitServices is used when there are explicit services that should be
	// restarted. This is used for the `snap restart snap-name.svc1` case,
	// where we create a task with specific services to work on - in this case
	// ExplicitServices ends up being the list of services that were explicitly
	// mentioned by the user to be restarted, regardless of their state. This is
	// needed because in the case that one does `snap restart snap-name`,
	// Services gets populated with all services in the snap, which we now
	// interpret to mean that only inactive services of that set are to be
	// restarted, but there could be additional explicit services that need to
	// be restarted at the same time in the case that someone does something
	// like `snap restart snap-name snap-name.svc1`, we will restart all the
	// inactive and not disabled services in snap-name, and also svc1 regardless
	// of the state svc1 is in.
	ExplicitServices []string `json:"explicit-services,omitempty"`
}

ServiceAction encapsulates a single service-related action (such as starting, stopping or restarting) run against services of a given snap. The action is run for services listed in services attribute, or for all services of the snap if services list is empty. The names of services and explicit-services are app names (as defined in snap yaml).

type ServiceActionConflictError

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

type ServiceManager

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

ServiceManager is responsible for starting and stopping snap services.

func Manager

func Manager(st *state.State, runner *state.TaskRunner) *ServiceManager

Manager returns a new service manager.

func (*ServiceManager) Ensure

func (m *ServiceManager) Ensure() error

Ensure implements StateManager.Ensure.

type StatusDecorator

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

StatusDecorator supports decorating client.AppInfos with service status.

func NewStatusDecorator

func NewStatusDecorator(rep interface {
	Notify(string)
}) *StatusDecorator

NewStatusDecorator returns a new StatusDecorator.

func (*StatusDecorator) DecorateWithStatus

func (sd *StatusDecorator) DecorateWithStatus(appInfo *client.AppInfo, snapApp *snap.AppInfo) error

DecorateWithStatus adds service status information to the given client.AppInfo associated with the given snap.AppInfo. If the snap is inactive or the app is not service it does nothing.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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