wrappers

package
v0.0.0-...-e46286a Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: GPL-3.0 Imports: 28 Imported by: 78

Documentation

Overview

Package wrappers is used to generate wrappers and service units and also desktop files for snap applications.

Index

Constants

View Source
const SnapdToolingMountUnit = "usr-lib-snapd.mount"

snapdToolingMountUnit is the name of the mount unit that provides the snapd tooling

Variables

This section is empty.

Functions

func AddSnapDBusActivationFiles

func AddSnapDBusActivationFiles(s *snap.Info) error

func DeriveSnapdDBusConfig

func DeriveSnapdDBusConfig(s *snap.Info) (sessionContent, systemContent map[string]osutil.FileState, err error)

func EnsureSnapBinaries

func EnsureSnapBinaries(s *snap.Info) (err error)

EnsureSnapBinaries updates the wrapper binaries for the applications from the snap which aren't services.

It also removes wrapper binaries from the applications of the old snap revision if it exists ensuring that only new snap binaries exist.

func EnsureSnapDesktopFiles

func EnsureSnapDesktopFiles(snaps []*snap.Info) error

EnsureSnapDesktopFiles puts in place the desktop files for the applications from the snap.

It also removes desktop files from the applications of the old snap revision to ensure that only new snap desktop files exist.

func EnsureSnapIcons

func EnsureSnapIcons(s *snap.Info) error

EnsureSnapIcons puts in place the icon files for the applications from the snap.

It also removes icon files from the applications of the old snap revision to ensure that only new snap icon files exist.

func EnsureSnapServices

func EnsureSnapServices(snaps map[*snap.Info]*SnapServiceOptions, opts *EnsureSnapServicesOptions, observeChange ObserveChangeCallback, inter Interacter) (err error)

EnsureSnapServices will ensure that the specified snap services' file states are up to date with the specified options and infos. It will add new services if those units don't already exist, but it does not delete existing service units that are not present in the snap's Info structures. There are two sets of options; there are global options which apply to the entire transaction and to every snap service that is ensured, and options which are per-snap service and specified in the map argument. If any errors are encountered trying to update systemd units, then all changes performed up to that point are rolled back, meaning newly written units are deleted and modified units are attempted to be restored to their previous state. To observe which units were added or modified a ObserveChangeCallback calllback can be provided. The callback is invoked while processing the changes. Because of that it should not produce immediate side-effects, as the changes are in effect only if the function did not return an error. This function is idempotent.

func RemoveQuotaGroup

func RemoveQuotaGroup(grp *quota.Group, inter Interacter) error

RemoveQuotaGroup ensures that the slice file for a quota group is removed. It assumes that the slice corresponding to the group is not in use anymore by any services or sub-groups of the group when it is invoked. To remove a group with sub-groups, one must remove all the sub-groups first. This function is idempotent, if the slice file doesn't exist no error is returned.

func RemoveSnapBinaries

func RemoveSnapBinaries(s *snap.Info) error

RemoveSnapBinaries removes the wrapper binaries for the applications from the snap which aren't services from.

func RemoveSnapDBusActivationFiles

func RemoveSnapDBusActivationFiles(s *snap.Info) error

func RemoveSnapDesktopFiles

func RemoveSnapDesktopFiles(s *snap.Info) error

RemoveSnapDesktopFiles removes the added desktop files for the applications in the snap.

func RemoveSnapIcons

func RemoveSnapIcons(s *snap.Info) error

RemoveSnapIcons removes the added icons for the applications in the snap.

func RemoveSnapServices

func RemoveSnapServices(s *snap.Info, inter Interacter) error

RemoveSnapServices disables and removes service units for the applications from the snap which are services. The optional flag indicates whether services are removed as part of undoing of first install of a given snap.

func RemoveSnapdSnapServicesOnCore

func RemoveSnapdSnapServicesOnCore(s *snap.Info, inter Interacter) error

RemoveSnapdSnapServicesOnCore removes the snapd services generated by a prior call to AddSnapdSnapServices. The core snap is used as the reference for restoring the system state, making this undo helper suitable for use when reverting the first installation of the snapd snap on a core device.

func RestartServices

func RestartServices(apps []*snap.AppInfo, explicitServices []string,
	flags *RestartServicesFlags, inter Interacter, tm timings.Measurer) error

Restart or reload active services in `svcs`. If reload flag is set then "systemctl reload-or-restart" is attempted. The services mentioned in `explicitServices` should be a subset of the services in svcs. The services included in explicitServices are always restarted, regardless of their state. The services in the `svcs` argument are only restarted if they are active, so if a service is meant to be restarted no matter it's state, it should be included in the explicitServices list. The list of explicitServices needs to use systemd unit names. TODO: change explicitServices format to be less unusual, more consistent (introduce AppRef?)

func StartServices

func StartServices(apps []*snap.AppInfo, disabledSvcs *DisabledServices, flags *StartServicesFlags, inter Interacter, tm timings.Measurer) (err error)

StartServices starts service units for the applications from the snap which are services. Service units will be started in the order provided by the caller.

func StopServices

func StopServices(apps []*snap.AppInfo, flags *StopServicesFlags, reason snap.ServiceStopReason, inter Interacter, tm timings.Measurer) error

StopServices stops and optionally disables service units for the applications from the snap which are services.

Types

type AddSnapdSnapServicesOptions

type AddSnapdSnapServicesOptions struct {
	// Preseeding is whether the system is currently being preseeded, in which
	// case there is not a running systemd for EnsureSnapServicesOptions to
	// issue commands like systemctl daemon-reload to.
	Preseeding bool
}

type DisabledServices

type DisabledServices struct {
	SystemServices []string
	UserServices   map[int][]string
}

DisabledServices represents an overview of which services in a snap are currently disabled, both of system services and user services. User services are indexed by the system uid as user services may run in one instance per user.

func QueryDisabledServices

func QueryDisabledServices(info *snap.Info, pb progress.Meter) (*DisabledServices, error)

QueryDisabledServices returns a list of all currently disabled snap services in the snap.

type EnsureSnapServicesOptions

type EnsureSnapServicesOptions struct {
	// Preseeding is whether the system is currently being preseeded, in which
	// case there is not a running systemd for EnsureSnapServicesOptions to
	// issue commands like systemctl daemon-reload to.
	Preseeding bool

	// RequireMountedSnapdSnap is whether the generated units should depend on
	// the snapd snap being mounted, this is specific to systems like UC18 and
	// UC20 which have the snapd snap and need to have units generated
	RequireMountedSnapdSnap bool

	// IncludeServices provides the option for allowing filtering which services
	// that should be configured. The service list must be in the format my-snap.my-service.
	// If this list is not provided, then all services will be included.
	IncludeServices []string
}

EnsureSnapServicesOptions is the set of options applying to the EnsureSnapServices operation. It does not include per-snap specific options such as VitalityRank or RequireMountedSnapdSnap from AddSnapServiceOptions, since those are expected to be provided in the snaps argument.

type Interacter

type Interacter interface {
	Notify(status string)
}

type ObserveChangeCallback

type ObserveChangeCallback func(app *snap.AppInfo, grp *quota.Group, unitType string, name, old, new string)

ObserveChangeCallback can be invoked by EnsureSnapServices to observe the previous content of a unit and the new on a change. unitType can be "service", "socket", "timer". name is empty for a timer.

type RestartServicesFlags

type RestartServicesFlags struct {
	// Reload set if we might need to reload the service definitions.
	Reload bool
	// AlsoEnabledNonActive set if we to restart also enabled but not running units
	AlsoEnabledNonActive bool
	ScopeOptions
}

RestartServicesFlags carries additional parameters for RestartServices. XXX: Rename to RestartServicesOptions

type ScopeOptions

type ScopeOptions struct {
	// Scope determines the types of services affected. This can be either
	// or both of system services and user services.
	Scope ServiceScope `json:"scope,omitempty"`
	// Users if set, determines which users the operation should include, if
	// the scope includes user services.
	Users []string `json:"users,omitempty"`
}

ScopeOptions provides ways to limit the effects of service operations to a certain scope, including which users and service type.

type ServiceScope

type ServiceScope string

ServiceScope indicates the scope of services that can be present in a snap, which may be affected by an operation.

const (
	// ServiceScopeAll indicates both system and user services of a snap.
	ServiceScopeAll ServiceScope = ""
	// ServiceScopeSystem indicates just the system services of a snap.
	ServiceScopeSystem ServiceScope = "system"
	// ServiceScopeUser indicates just the user services of a snap.
	ServiceScopeUser ServiceScope = "user"
)

type SnapServiceOptions

type SnapServiceOptions struct {
	// VitalityRank is the rank of all services in the specified snap used by
	// the OOM killer when OOM conditions are reached.
	VitalityRank int

	// QuotaGroup is the quota group for the specified snap.
	QuotaGroup *quota.Group
}

type SnapdRestart

type SnapdRestart interface {
	Restart() error
}

SnapdRestart keeps state of services that need a restart after current symlink of snapd snap (/snap/snapd/current) has been updated. Call Restart method then. Currently, the list of services is static and the absence of a SnapdRestart object (nil), means no service requires a restart.

func AddSnapdSnapServices

func AddSnapdSnapServices(s *snap.Info, opts *AddSnapdSnapServicesOptions, inter Interacter) (SnapdRestart, error)

AddSnapdSnapServices sets up the services based on a given snapd snap in the system.

type StartServicesFlags

type StartServicesFlags struct {
	Enable bool
	ScopeOptions
}

StartServicesFlags carries additional parameters for StartService. XXX: Rename to StartServiceOptions

type StopServicesFlags

type StopServicesFlags struct {
	Disable bool
	ScopeOptions
}

StopServicesFlags carries additional parameters for StopServices. XXX: Rename to StopServicesOptions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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