servicestate

package
v0.0.0-...-5ca13c7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: GPL-3.0 Imports: 37 Imported by: 47

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func AddSnapToQuotaGroup

func AddSnapToQuotaGroup(st *state.State, snapName string, quotaGroup string) (*state.Task, error)

AddSnapToQuotaGroup returns a task for adding a snap to a quota group. It wraps the task creation with proper conflict detection for the affected quota-group. Conflict detection for the snap being added must be done by the larger context, as this function is intended to be used in the context of a more complex change.

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, cu *user.User, 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, createOpts CreateQuotaOptions) (*state.TaskSet, error)

CreateQuota attempts to create the specified quota group with the specified snaps in it.

func EnsureQuotaUsability

func EnsureQuotaUsability() (restore func())

EnsureQuotaUsability is exported for unit tests from other packages to re-run the init() time checks for quota usability which set the errors which quotaGroupsAvailable() checks for. It saves the previous state of the usability errors to be restored via the provided restore function.

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 LogReader

func LogReader(appInfos []*snap.AppInfo, n int, follow bool) (io.ReadCloser, error)

LogReader returns an io.ReadCloser which produce logs for the provided snap AppInfo's. It is a convenience wrapper around the systemd.LogReader implementation.

func MockEnsuredSnapServices

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

func NewStatusDecorator

func NewStatusDecorator(rep interface {
	Notify(string)
}) clientutil.StatusDecorator

NewStatusDecorator returns a new StatusDecorator.

Using NewStatusDecorator will only allow for global status of user-services as StatusDecorator is designed to contain a single set of results for a single user.

func NewStatusDecoratorForUid

func NewStatusDecoratorForUid(rep interface {
	Notify(string)
}, context context.Context, uid string) clientutil.StatusDecorator

NewStatusDecoratorForUid returns a new StatusDecorator, but configured for a specific uid. This allows the StatusDecorator to get statuses for user-services for a specific user.

func RegisterAffectedQuotasByKind

func RegisterAffectedQuotasByKind(kind string, f AffectedQuotasFunc)

RegisterAffectedQuotasByKind registers an AffectedQuotasFunc for returning the affected quotas for tasks of the given kind, to use in conflicts detection.

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, snapInfo *snap.Info, quotaGroups map[string]*quota.Group) (opts *wrappers.SnapServiceOptions, err error)

SnapServiceOptions computes the options to configure services for the given snap. 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 UpdateQuotaOptions) (*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 AffectedQuotasFunc

type AffectedQuotasFunc func(*state.Task) ([]string, error)

An AffectedQuotasFunc returns a list of affected quota group names for the given supported task.

type CreateQuotaOptions

type CreateQuotaOptions struct {
	// ParentName is the name of the parent quota group, the group should be
	// placed under.
	ParentName string

	// Snaps is the set of snaps to add to the quota group. These are
	// instance names of snaps.
	Snaps []string

	// Services is the set of services to add to the quota group. These are
	// formatted as my-snap.my-service.
	Services []string

	// ResourceLimits is the resource limits to be used for the quota group.
	ResourceLimits quota.Resources
}

CreateQuotaOptions reflects all of options available when creating new quota groups.

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"`
	Scope  client.ScopeSelector `json:"scope"`
	Users  client.UserSelector  `json:"users"`
	client.StartOptions
	client.StopOptions
	client.RestartOptions
}

func (*Instruction) EnsureDefaultScopeForUser

func (i *Instruction) EnsureDefaultScopeForUser(u *user.User)

EnsureDefaultScopeForUser sets up default scopes based on the type of user if none were provided. Make sure to call Instruction.Validate() before calling this.

func (*Instruction) ServiceScope

func (i *Instruction) ServiceScope() wrappers.ServiceScope

func (*Instruction) Validate

func (i *Instruction) Validate(u *user.User, apps []*snap.AppInfo) error

Validate validates the some of the data members in the Instruction. Currently this validates user-list and scope. This should only be called once when the structure is initialized/deserialized.

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,omitempty"`

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

	// 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,omitempty"`

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

	// ResourceLimits is the set of resource limits to set on the quota group.
	// 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.
	ResourceLimits quota.Resources `json:"resource-limits,omitempty"`

	// 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 `json:"parent-name,omitempty"`
}

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

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"`
	// RestartEnabledNonActive is only for "restart" and
	// "reload-or-restart" actions, and when set it restarts also enabled
	// non-running services, otherwise these services are left inactive.
	RestartEnabledNonActive bool `json:"restart-enabled-non-active,omitempty"`
	wrappers.ScopeOptions
}

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 (*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.

type UpdateQuotaOptions

type UpdateQuotaOptions 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

	// AddServices is the set of snap services to add to the quota group. These are
	// names of the format <snap.service>, and are appended to the existing services in
	// the quota group
	AddServices []string

	// NewResourceLimits is the new resource limits to be used for the quota group. A
	// limit is only changed if the corresponding limit is != nil.
	NewResourceLimits quota.Resources
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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