snap

package
v0.0.0-...-6dcaeb9 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package snap manages installing and running snaps.

Index

Constants

View Source
const (
	// Command is a path to the snap binary, or to one that can be detected by os.Exec
	Command = "snap"
)

Variables

This section is empty.

Functions

func SetSnapConfig

func SetSnapConfig(snap string, key string, value string) error

SetSnapConfig sets a snap's key to value.

Types

type App

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

App is a wrapper around a single snap

func (*App) AcknowledgeAssertsArgs

func (a *App) AcknowledgeAssertsArgs() []string

AcknowledgeAssertsArgs returns args to acknowledge the asserts for the snap required to install this application. Returns nil if none are required.

func (*App) BackgroundServices

func (a *App) BackgroundServices() []BackgroundService

BackgroundServices returns a list of background services that are required to be installed for the main application to run.

func (*App) InstallArgs

func (a *App) InstallArgs() []string

InstallArgs returns a way to install one application with all it's settings.

func (*App) Name

func (a *App) Name() string

Name returns the name of the application

func (*App) Prerequisites

func (a *App) Prerequisites() []Installable

Prerequisites defines a list of all the Prerequisites required before the application also needs to be installed.

func (*App) StartCommands

func (a *App) StartCommands(executable string) []string

StartCommands returns a list if shell commands that should be executed (in order) to start App and its background services. executeable is a path to the snap executable. If the app has prerequisite applications defined, then take care to call StartCommands on those apps also.

func (*App) Validate

func (a *App) Validate() error

Validate will validate a given application for any potential issues.

type BackgroundService

type BackgroundService struct {
	// name is the name of the service, without the snap name.
	// For example , for the`juju-db.daemon` service, use the name `daemon`.
	Name string

	// enableAtStartup determines whether services provided
	// by the snap should be started with the `--enable` flag
	EnableAtStartup bool
}

BackgroundService represents the a service that snaps define. For example, the multipass snap includes the libvirt-bin and multipassd background services.

func (*BackgroundService) Validate

func (backgroundService *BackgroundService) Validate() error

Validate checks that the construction parameters of backgroundService are valid. Successful validation returns nil.

type ConfinementPolicy

type ConfinementPolicy string

ConfinementPolicy describes the confinement policy for installing a given snap application.

const (
	// StrictPolicy confined snaps run in complete isolation, up to a minimal
	// access level that’s deemed always safe.
	StrictPolicy ConfinementPolicy = "strict"
	// ClassicPolicy allows access to your system’s resources in much the same
	// way traditional packages do
	ClassicPolicy ConfinementPolicy = "classic"
	// DevModePolicy is a special mode for snap creators and developers.
	// A devmode snap runs as a strictly confined snap with full access to
	// system resources, and produces debug output to identify unspecified
	// interfaces.
	DevModePolicy ConfinementPolicy = "devmode"
	// JailModePolicy enforces the confinement model for a snap to ensure that
	// the confinement is enforced.
	JailModePolicy ConfinementPolicy = "jailmode"
)

func (ConfinementPolicy) String

func (p ConfinementPolicy) String() string

String representation of the confinement policy.

func (ConfinementPolicy) Validate

func (p ConfinementPolicy) Validate() error

Validate validates a given confinement policy to ensure it matches the ones we expect.

type Installable

type Installable interface {
	// Name returns the name of the application
	Name() string

	// InstallArgs returns args to install this application with all it's settings.
	InstallArgs() []string

	// AcknowledgeAssertsArgs returns args to acknowledge the asserts for the snap
	// required to install this application. Returns nil is none are required.
	AcknowledgeAssertsArgs() []string

	// Validate will validate a given application for any potential issues.
	Validate() error

	// StartCommands returns a list if shell commands that should be executed
	// (in order) to start App and its background services.
	StartCommands(executable string) []string

	// Prerequisites defines a list of all the Prerequisites required before the
	// application also needs to be installed.
	Prerequisites() []Installable

	// BackgroundServices returns a list of background services that are
	// required to be installed for the main application to run.
	BackgroundServices() []BackgroundService
}

Installable represents an installable snap.

type Runnable

type Runnable interface {
	Execute(name string, args ...string) (string, error)
}

Runnable expects to be able to run a given command with a series of arguments and return the output and/or error from that executing command.

type Service

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

Service is a type for services that are being managed by snapd as snaps.

func NewService

func NewService(config ServiceConfig) (Service, error)

NewService returns a new Service defined by `conf`, with the name `serviceName`. The Service abstracts service(s) provided by a snap.

If no BackgroundServices are provided, Service will wrap all of the snap's background services.

func (Service) ConfigOverride

func (s Service) ConfigOverride() error

ConfigOverride writes a systemd override to enable the specified limits to be used by the snap.

func (Service) Exists

func (s Service) Exists() (bool, error)

Exists is not implemented for snaps.

func (Service) Install

func (s Service) Install() error

Install installs the snap and its background services.

func (Service) Installed

func (s Service) Installed() (bool, error)

Installed returns true if the service has been successfully installed.

func (Service) IsLocal

func (s Service) IsLocal() bool

IsLocal returns true if the snap is installed locally.

func (Service) Name

func (s Service) Name() string

Name returns the service's name. It should match snap's naming conventions, e.g. <snap> for all services provided by <snap> and `<snap>.<app>` for a specific service under the snap's control.For example, the `juju-db` snap provides a `daemon` service. Its name is `juju-db.daemon`.

func (Service) Restart

func (s Service) Restart() error

Restart restarts the service, or starts if it's not currently running.

Restart is part of the service.RestartableService interface

func (Service) Running

func (s Service) Running() (bool, error)

Running returns (true, nil) when snap indicates that service is currently active.

func (Service) Start

func (s Service) Start() error

Start starts the service, returning nil when successful. If the service is already running, Start does not restart it.

func (Service) StartCommands

func (s Service) StartCommands() ([]string, error)

StartCommands returns a slice of strings. that are shell commands to be executed by a shell which start the service.

func (Service) Stop

func (s Service) Stop() error

Stop stops a running service. Returns nil when the underlying call to `snap stop <service-name>` exits with error code 0.

func (Service) Validate

func (s Service) Validate() error

Validate validates that snap.Service has been correctly configured. Validate returns nil when successful and an error when successful.

type ServiceConfig

type ServiceConfig struct {
	// ServiceName is the name of this snap service.
	ServiceName string

	// SnapPath is an optional parameter that specifies the path on the filesystem
	// to install the snap from. If SnapPath is not provided, the snap will be
	// installed from the snap store.
	SnapPath string

	// SnapAssertsPath is an optional parameter that specifies the path on the
	// filesystem for any asserts that need to be acknowledged before installing.
	SnapAssertsPath string

	// Conf is responsible for defining services. Its fields
	// represent elements of a service configuration.
	Conf common.Conf

	// ConfigDir represents the directory path where the configuration files for
	// a service in a snap are located.
	ConfigDir string

	// Channel represents the channel to install the snap from, if we are installing
	// from the snap store.
	Channel string

	// SnapExecutable is the path where we can find the executable for snap itself.
	SnapExecutable string

	// ConfinementPolicy represents the confinement policy for installing a
	// snap application. It can have the following values: "strict", "classic",
	// "devmode", "jailmode". The "strict" policy enforces strict security
	// confinement, "classic" allows access to system resources, "devmode"
	// disables all confinement, and "jailmode" runs the snap in an isolated
	// environment.snap's confinement policy.
	ConfinementPolicy ConfinementPolicy

	// BackgroundServices represents a slice of background services required
	// by this snap service. When this service is started, these background
	// services will also be started.
	BackgroundServices []BackgroundService

	// Prerequisites represents a slice of prerequisite applications that need
	// to be installed to install this application.
	Prerequisites []Installable
}

Jump to

Keyboard shortcuts

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