Documentation
¶
Overview ¶
Package snap is a minimal service.Service implementation, derived from the on service/upstart package.
Index ¶
- Constants
- Variables
- func IsRunning() (bool, error)
- func ListCommand() string
- func ListServices() ([]string, error)
- func SetSnapConfig(snap string, key string, value string) error
- type App
- type BackgroundService
- type Service
- func (s Service) Conf() common.Conf
- func (s Service) Exists() (bool, error)
- func (s Service) Install() error
- func (s Service) InstallCommands() ([]string, error)
- func (s Service) Installed() (bool, error)
- func (s Service) Name() string
- func (s Service) Remove() error
- func (s *Service) Restart() error
- func (s Service) Running() (bool, error)
- func (s Service) Start() error
- func (s Service) StartCommands() ([]string, error)
- func (s Service) Stop() error
- func (s Service) Validate() error
Constants ¶
const (
// Command is a path to the snap binary, or to one that can be detected by os.Exec
Command = "snap"
)
Variables ¶
var ( // ConfinementPolicies represents the legal flags for installing a snap ConfinementPolicies = set.NewStrings("devmode", "classic", "jailmode") // Channels represents the legal channels for installing a snap Channels = set.NewStrings("edge", "beta", "candidate", "stable") )
Functions ¶
func IsRunning ¶
IsRunning indicates whether Snap is currently running on the system. When the snap command (normally installed to /usr/bin/snap) cannot be detected, IsRunning returns (false, nil). Other errors result in (false, err).
func ListCommand ¶
func ListCommand() string
ListCommand returns a command that will be interpreted by a shell to produce a list of currently-installed services that are managed by snap.
func ListServices ¶
ListServices returns a list of services that are being managed by snap.
Types ¶
type App ¶
type App struct {
Name string
ConfinementPolicy string
Channel string
BackgroundServices []BackgroundService
Prerequisites []App
}
App is a wrapper around a single snap
func (*App) StartCommands ¶
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.
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 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(name string, conf common.Conf, snapPath string, Channel string, ConfinementPolicy string, backgroundServices []BackgroundService, prerequisites []App) (Service, error)
NewService returns a new Service defined by `conf`, with the name `name`. If no BackgroundServices are provided, manage all of the snap's background services together.
func NewServiceFromName ¶
NewServiceFromName returns a service that manages all of a snap's services as if they were a single service. NewServiceFromName uses the name parameter to fetch and install a snap with a matching name, then uses default policies for the installation. To install a snap with --classic confinement, or via --edge, --candidate or --beta, then create the Service via another method.
func (Service) Conf ¶
Conf returns the service's configuration.
Conf is part of the service.Service interface.
func (Service) Exists ¶
Exists is not implemented for snaps.
Exists is part of the service.Service interface.
func (Service) Install ¶
Install installs the snap and its background services.
Install is part of the service.Service interface.
func (Service) InstallCommands ¶
InstallCommands returns a slice of shell commands that is executed independently, in serial, by a shell. When the final command returns with a 0 exit code, the installation will be deemed to have been successful.
InstallCommands is part of the service.Service interface
func (Service) Installed ¶
Installed returns true if the service has been successfully installed.
Installed is part of the service.Service interface.
func (Service) Name ¶
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`.
Name is part of the service.Service interface
func (Service) Remove ¶
Remove uninstalls a service, . Returns nil when the underlying call to `snap remove <service-name>` exits with error code 0.
Remove is part of the service.ServiceActions interface.
func (*Service) Restart ¶
Restart restarts the service, or starts if it's not currently running.
Restart is part of the service.RestartableService interface
func (Service) Running ¶
Running returns (true, nil) when snap indicates that service is currently active.
func (Service) Start ¶
Start starts the service, returning nil when successful. If the service is already running, Start does not restart it.
Start is part of the service.ServiceActions interface
func (Service) StartCommands ¶
StartCommands returns a slice of strings. that are shell commands to be executed by a shell which start the service.