Defining a command
Exposing executable components
A snap’s executable is exposed to the host system via the top-level
apps section of snapcraft.yaml. Its name needs to correspond with part name responsible for staging the executable within your snap.
For example, here’s a complete snapcraft.yaml for a fully-functional snap:
name: os-release base: core20 version: '0.2' summary: Outputs the contents of /etc/os-release description: Prints the contents of os-release grade: stable confinement: strict apps: part-os-release: command: bin/os-release.sh parts: part-os-release: plugin: dump source: . organize: os-release.sh: bin/
The above example creates a snap from the following simple script, called
os-release.sh, located within the top-level snap of the directory:
#! /bin/sh cat /etc/os-release
Make sure the above script is executable by running the following command on the build host after creating the script:
$ chmod +x os-release.sh
os-release.sh executable is brought into the snap via
part-os-release, which is a part using the dump plugin. It then uses
organize to copy the os-release.sh file into the snap’s
bin/ directory before the top-level apps section exposes the
bin/os-release.sh executable to the host system
If you need to add user configurable options to your service or daemon, such as which port it should use, see Adding snap configuration.
See Tab completion if you wish to add command line tab completion to your snap.
Interfaces enable an app to access system resources. Interfaces that are required for normal operation are specified at snap build-time within the above
appmetadata of a snap’s snapcraft.yaml. See Adding Interfaces for more details.
Last updated 6 months ago.