Disabled snap gets enabled after a refresh

Hi,

We recently released microk8s and one of our users reported that the snap got enabled even though he had explicitly disabled it. Here is the snap changes and tasks you requested.

$ snap changes                                                                                                                                                           130 ↵
ID   Status  Spawn                    Ready                    Summary
418  Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Auto-refresh snap "microk8s"
419  Done    today at 11:46 CEST      today at 11:46 CEST      Running service command
420  Done    today at 14:02 CEST      today at 14:02 CEST      Running service command
$ snap tasks 418
Status  Spawn                    Ready                    Summary
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Ensure prerequisites for "microk8s" are available
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Download snap "microk8s" (185) from channel "edge"
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Fetch and check assertions for snap "microk8s" (185)
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Mount snap "microk8s" (185)
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Run pre-refresh hook of "microk8s" snap if present
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Stop snap "microk8s" services
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Remove aliases for snap "microk8s"
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Make current revision for snap "microk8s" unavailable
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Copy snap "microk8s" data
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Setup snap "microk8s" (185) security profiles
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Make snap "microk8s" (185) available to the system
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Automatically connect eligible plugs and slots of snap "microk8s"
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Set automatic aliases for snap "microk8s"
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Setup snap "microk8s" aliases
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Run post-refresh hook of "microk8s" snap if present
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Start snap "microk8s" (185) services
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Remove data for snap "microk8s" (176)
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Remove snap "microk8s" (176) from the system
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Clean up "microk8s" (185) install
Done    yesterday at 22:16 CEST  yesterday at 22:16 CEST  Run configure hook of "microk8s" snap if present

Is there a way for the snap to prevent this?

Thanks

It’s a bug. We’ll fix it.

I’ve just tested this, and cannot reproduce it: I installed a known-old revision of one of my snaps,

$ snapcraft revisions http
Rev.    Uploaded              Arch       Version        Channels
22      2018-05-23T11:53:29Z  Arch: All  0.9.9-1.1      -
21      2017-08-03T09:32:05Z  Arch: All  0.9.9-1        candidate*, stable*, stable/it-was-the-best-of-times--it-was-the-worst-of-times--it-was-the-age-of-wisdom--it-was-the-age-of-foolishness
20      2017-08-03T09:12:40Z  Arch: All  0.9.9-0        candidate
19      2016-08-14T08:53:29Z  Arch: All  0.9.6-0        stable, candidate, beta, edge
18      2016-08-03T10:23:30Z  Arch: All  4.66920160910  stable, candidate, beta, edge
17      2016-06-02T14:27:33Z  Arch: All  4.6692016091   stable, candidate, beta, edge
16      2016-05-10T14:02:23Z  Arch: All  4.669201609    stable, candidate, beta, edge
15      2016-05-09T21:23:55Z  Arch: All  4.66920160     stable, candidate, beta, edge
14      2016-04-20T09:22:50Z  Arch: All  4.6692016      stable, candidate, beta, edge
$ snap install --revision=19 --stable http
http 0.9.6-0 from John Lenton (chipaca) installed
$ snap disable http
http disabled
$ snap refresh http
error: cannot refresh "http": refreshing disabled snap "http" not supported
$ snap refresh 
All snaps up to date.
$ snap list http
Name  Version  Rev  Tracking  Publisher  Notes
http  0.9.6-0  19   stable    chipaca    disabled
$ snap enable http
http enabled
$ snap refresh 
http 0.9.9-1 from John Lenton (chipaca) refreshed

could I please have steps-to-reproduce?

Oh! you disabled the service! Sorry, I missed that. That’s fixed by

Was the service disabled i.e. through snapctl stop --disable SERVICE in a hook, or was the entire snap itself disabled through snap disable SNAP?

I don’t think disabling a snap’s services blocks it from refreshing, so I don’t think my PR will affect that in any case.

I don’t think my PR @chipaca linked to will fix the snap disable SNAP issue, that sounds like a separate bug.

Sorry for the confusion with this (I’m the one this happened to).

It wasn’t a snap that was disabled, but one that was explicitly stopped.

I snap stop microk8s and went on my business. Several hours later, I noticed that microk8s was running again, which was initially confusing. We had a new release pushed to edge, and during the upgrade the service was restarted.

I expected (right or wrongly) that when I stopped the service, that it wouldn’t be started until I explicitly did so, or rebooted. For background refreshing applications, I’d hope they would maintain the state I put it in (stopped or running) post-upgrade, but that’s more of a usage issue rather than a bug maybe.

I think you probably had meant to do snap stop --disable microk8s instead of snap stop microk8s, as the --disable flag is supposed to prevent the service from starting again, even when refreshed/rebooted, etc.

However, I now see @chipaca’s point about my PR, because currently snapd will always start services whether they are disabled or not during refresh/install, and my PR makes it so that disabled services don’t get started automatically.

I think that it’s expected behavior for a stopped service to come up again if it gets refreshed, as that’s effectively the same as if the system was rebooted. However for disabled services it shouldn’t ever get restarted automatically.

1 Like

I keep seeing this. Here is what I do to reproduce:

sudo snap install microk8s --classic
sudo snap stop --disable microk8s
sudo snap refresh microk8s --channel edge

And using systemctl status snap.microk8s.daemon-apiserver I can see the service stopping and starting again after the refresh.

This is a separate snapd bug: https://bugs.launchpad.net/snapd/+bug/1818306
Unfortunately the fix mentioned above only works for install, not refresh