This thread summaries an upcoming feature of snapd that is something many application developers were asking for a long while now. Internally we call it refresh-app-awareness
because it means snapd is aware of running applications and will inhibit refreshes of snaps with apps running. The feature is smart enough to filter out services that are restarted during refresh.
Current Status
The feature is currently under development, coming to snapd 2.39 behind a feature flag, that is, it will require opt-in from the user, like some of the other features being introduced did, until it is deemed stable for general use.
The feature can be tracked in GitHub using https://github.com/snapcore/snapd/projects/3
There’s an older thread that has a lot of the back story here Bug? Saves are blocked to $SNAP_USER_DATA if snap updates when it is already running
Preconditions
To enable the feature you must be on snapd 2.39 or newer. On Ubuntu and Debian you can simply refresh the core
snap to the edge channel to do so. You can always refresh back to stable if you don’t want to test unstable software that might interfere with your system.
To use the feature now run:
snap set core experimental.refresh-app-awareness=true
NOTE: If this doesn’t work the version of snapd you are using is not recent enough. Just try again on the next refresh from edge. It should be available soon.
Ideally you should restart all the running snap applications (e.g. reboot if you want to) as process accounting that is used by the feature internally will only start from this point onward. If you, for whatever reason, want to disable the feature simply run:
snap set core experimental.refresh-app-awareness=false
Usage
Having this option set you can try to manually refresh a snap to another channel or to simply refresh to a new revision arriving on edge. For as long as the snap is busy it the refresh will be inhibited. A snap is busy if it has running non-service applications or hooks.
Future work
The feature will eventually support termination notification and will be able to refresh a snap the moment the last app in use is closed. There are some early plans for allowing applications to be notified of a pending refresh but that is further down the line as it has some complex dependencies that are not ready yet.