The majority of snaps expose their functionality via applications that run on the local system. Most of these applications are started either from the command line, the graphical desktop, or as services that run automatically.
A single snap may provide multiple applications and services. With a database snap, for example, you might expect an interactive client application alongside the service daemon.
Snaps manage their own services without the need for manual intervention. However, experienced administrators may want to interact with a snap’s services to help improve their integration with the local environment. For that reason, snapd offers a set of commands to allow a snap’s services to be inspected and their statuses changed.
snap services to lists all the services added to the system by the currently installed and enabled snaps:
$ snap services Service Startup Current Notes bluez.bluez enabled inactive - bluez.obex enabled inactive - cups.cups-browsed enabled active - cups.cupsd enabled active - docker.dockerd enabled active - juju.fetch-oci disabled inactive - lxd.activate enabled inactive - lxd.daemon enabled inactive socket-activated lxd.user-daemon enabled inactive socket-activated multipass.multipassd enabled inactive - nextcloud.apache disabled inactive - nextcloud.logrotate disabled inactive - nextcloud.mdns-publisher disabled inactive - nextcloud.mysql disabled inactive - nextcloud.nextcloud-cron disabled inactive - nextcloud.nextcloud-fixer disabled inactive - nextcloud.php-fpm disabled inactive - nextcloud.redis-server disabled inactive - nextcloud.renew-certs disabled inactive -
Adding a snap name as an argument will list only those services added by that snap:
$ snap services lxd Service Startup Current Notes lxd.activate enabled inactive - lxd.daemon enabled inactive socket-activated lxd.user-daemon enabled inactive socket-activated
The output includes the service name, whether the service is started when the system starts up, and whether it’s currently running.
Services are restarted using the
snap restart <snap name> command. This may be necessary if you’ve made custom changes to the snap application, for example, which the service needs to reload.
By default, all services for a specified snap will be restarted:
$ sudo snap restart lxd Restarted.
Using a more specific service name performs the same operation on an individual service:
$ sudo snap restart lxd.daemon Restarted.
The option to perform an operation on all of a snap’s services, or on one specific service, is common to all commands that operate on services.
If a service supports reloading, enabling the service to remain running while loading a new configuration, this can be requested with the
$ sudo snap restart --reload lxd.daemon Restarted.
Starting and stopping services
stop commands control whether a service should be currently running:
$ sudo snap stop lxd.daemon Stopped. $ sudo snap start lxd.daemon Started.
As mentioned above, these commands can operate both on individual snap’s services and on all services for a named snap, depending on the parameter provided.
To prevent a service from starting on the next boot, use the
$ sudo snap stop --disable lxd.daemon
The start command includes an
--enable option to re-enable the automatic starting of a service when the system boots:
$ sudo snap start --enable lxd.daemon
If you need to see the log output for a snap’s services, use the
command. As with the services command, you can specify either a snap name to
see the logs for all the services it contains, or the name of a specific
service within a snap:
$ sudo snap logs lxd 2018-09-14T10:38:23Z lxd.daemon: => LXD is ready (...) $ sudo snap logs lxd.daemon 2022-07-15T17:13:04+01:00 lxd.daemon: => LXD exited cleanly 2022-07-15T17:13:04+01:00 lxd.daemon: ==> Stopped LXD 2022-07-15T17:13:04+01:00 lxd.daemon: => Stopping LXCFS 2022-07-15T17:13:04+01:00 lxd.daemon: Running destructor lxcfs_exit 2022-07-15T17:13:05+01:00 lxd.daemon: ==> Stopped LXCFS 2022-07-15T17:13:05+01:00 lxd.daemon: => Cleaning up PID files 2022-07-15T17:13:05+01:00 lxd.daemon: => Cleaning up namespaces 2022-07-15T17:13:05+01:00 lxd.daemon: => All done 2022-07-15T17:13:05+01:00 systemd: snap.lxd.daemon.service: Deactivated successfully. 2022-07-15T17:13:05+01:00 systemd: Stopped Service for snap application lxd.daemon.
By default, only the last 10 lines are output. This can be changed with the
-n= option which can accept either a number or
all for the entire log:
snap logs -n=all lxd.daemon
-f option will keep log output open so you can follow new entries as they occur:
$ sudo snap logs lxd -f
The size and rate of log output can be limited by placing a snap within a quota group. See Journal log limits for more details.
Last updated 29 days ago.