Have a snap be run only when started manually?


I currently can’t upgrade a machine from ubuntu 18.04 to 20.04 because of a shortcoming in snapd.


On an 18.04 machine, I am running LXD container virtualization, where LXD is coming as a regular debian package, controlled with systemd. Since the LXD containers are kept in an encrypted file system, which requires a password to be entered, the systemd services for LXD are disabled and can be started after the password has been entered. That’s possible because systemd allows to set services on disabled and still allows to start them with systemctl start … without changing the state of disabled.

For ubuntu 20.04 the LXD package has been turned into a snap.

The problem with snaps is, that it can disable and enable snaps, but cannot start them without toggling its state. Therefore once the password is given and snap LXD run by enabling it, it would remain in enabled state even after reboot.

How would I keep an snap in a disabled state, but start it manually without making it enabled at next boot? (i.e. to run it only after a password for the encrypted partition has been entered)


1 Like
$ snap help stop
  snap stop [stop-OPTIONS] <service>...

The stop command stops, and optionally disables, the given services.

[stop command options]
      --no-wait      Do not wait for the operation to finish but just print the change id.
      --disable      As well as stopping the service now, arrange for it to no longer be started on boot.

[stop command arguments]
  <service>:         A service specification, which can be just a snap name (for all services in the snap), or <snap>.<app> for a single service.

you would use:

sudo snap stop --disable lxd

and after boot, when you want to use it:

sudo snap start lxd

(if you want to permanently enable it again you can use start --enable)

Yeah, that’s what I tried before asking the question:

# snap start lxd
error: cannot perform the following tasks:
- start of [lxd.activate lxd.daemon] (# systemctl start snap.lxd.activate.service snap.lxd.daemon.service
Failed to start snap.lxd.activate.service: Unit snap.lxd.activate.service not found.
Failed to start snap.lxd.daemon.service: Unit snap.lxd.daemon.service not found.
- start of [lxd.activate lxd.daemon] (exit status 5)

Seems as if you can’t start a disabled service, since the systemd units have been removed when disabling it. You have to enable before and that’s where the problem began…

works fine here … weird …

ogra@acheron:~$ sudo snap stop --disable lxd
ogra@acheron:~$ sudo snap start lxd