Refresh control

It would be great to see the gate-auto-refresh hook documented along with the other hooks in Supported snap hooks and wherever that page migrated to in the ReadTheDocs.

I have a few questions at the moment:

  1. Does the gate-auto-refresh hook run before or after the pre-refresh hook? And if it runs before but sets snapctl refresh --hold, does that prevent the pre-refresh hook from running?
  2. How does snapctl refresh --hold and snapctl refresh --proceed called from within hooks/scripts interact with settings the user has set with snap refresh --hold <snapname>? If the user has set a hold, is the snap capable of un-holding itself (I assume that would be bad)?
  3. I’m curious about the output of snapctl refresh --pending: does it return “inhibited” if there was a snapctl refresh --hold and/or snap refresh --hold <snapname>?
  4. What happens when snapctl refresh --proceed is called? Does it immediately trigger a refresh (assuming a previous refresh was held by a gate-auto-refresh hook call to snapctl refresh --hold)? Does the gate-auto-refresh hook get run again, and/or the pre-refresh hook?
  5. If the snap refresh is inhibited by a hold on one of its dependencies, what happens if snapctl refresh --proceed is called? I assume it still doesn’t proceed until the dependency is un-held?

I think refresh control could be an excellent solution to the problem of creating e.g. database backups before performing a refresh. There’s a timeout in the pre-refresh hook (30s I believe), so if the database backup would take too long, it could be killed and the refresh would fail. I think the gate-auto-refresh hook could be used to avoid this by holding the refresh, triggering a backup service to run separately, then that backup script would run snapctl refresh --proceed when it’s done creating the backup.