Add support for hooks

Bug #1586465 reported by Kyle Fazzari
28
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Canonical Click Reviewers tools (obsolete)
Fix Released
Undecided
Jamie Strandboge
Snapcraft
Fix Released
Wishlist
Kyle Fazzari
snapd (Ubuntu)
Fix Released
Wishlist
Kyle Fazzari

Bug Description

There are a number of situations where snapd needs to notify a snap that something has happened. For example, when a snap is upgraded, the snap may need to run some sort of migration on the previous version’s data in order to make it consumable by the new version. This is possible today, but it requires that the snap be smart enough to realize that it’s running on old data, and there’s no way for the snap to inform snapd that the upgrade failed.

A new global section should be added to the `snap.yaml` (alongside `apps`), called "hooks." To continue with the example of an upgrade, such a section would look something like this:

    hooks:
      upgrade: # Actual name TBD
        plugs: [network]

The name of the hook ("upgrade" in this example) directly corresponds to its purpose, and must be one of the yet-to-be-determined hooks supported by snapd. It also directly corresponds to the file name of the hook executable, which by convention is to be placed into the `meta/hooks/` directory within the snap. Similar to apps, the hooks may utilize plugs in order to extend their capabilities. Note that if the hook doesn't require any plugs, it doesn't need to be present in the YAML at all (i.e. its presence in `meta/hooks/` is enough for snapd to know it should be run).

Hooks may be written in any language that is available to the snap. They will be called with no parameters-- if hooks need information from snapd it can be obtained via a yet-to-be-determined API call.

If the hook returns a non-zero exit code the hook is considered to have failed, and snapd will take remedial action accordingly. The action taken depends on system choices made for the hook being run. Potential actions are retrying, or failure which would cause the whole change to be undone per existing semantics.

Kyle Fazzari (kyrofa)
Changed in snapd (Ubuntu):
importance: Undecided → Wishlist
Changed in snapcraft:
importance: Undecided → Wishlist
Changed in snapd (Ubuntu):
assignee: nobody → Kyle Fazzari (kyrofa)
status: New → In Progress
Kyle Fazzari (kyrofa)
description: updated
Revision history for this message
Kyle Fazzari (kyrofa) wrote :
Revision history for this message
Kyle Fazzari (kyrofa) wrote :
Revision history for this message
Kyle Fazzari (kyrofa) wrote :
Revision history for this message
Kyle Fazzari (kyrofa) wrote :

Load and validate implicit hooks: https://github.com/snapcore/snapd/pull/1329

Revision history for this message
Kyle Fazzari (kyrofa) wrote :

Starting interface work: start using security tags instead of app names: https://github.com/snapcore/snapd/pull/1332

Revision history for this message
Kyle Fazzari (kyrofa) wrote :
Revision history for this message
Kyle Fazzari (kyrofa) wrote :
Revision history for this message
Kyle Fazzari (kyrofa) wrote :
Revision history for this message
Kyle Fazzari (kyrofa) wrote :
Revision history for this message
Kyle Fazzari (kyrofa) wrote :
Revision history for this message
Kyle Fazzari (kyrofa) wrote :
Revision history for this message
Kyle Fazzari (kyrofa) wrote :
Revision history for this message
Kyle Fazzari (kyrofa) wrote :

Actually start running hooks: https://github.com/snapcore/snapd/pull/1511

Revision history for this message
Kyle Fazzari (kyrofa) wrote :

The snapctl command to be used within hooks to communicate with snapd: https://github.com/snapcore/snapd/pull/1667

Revision history for this message
Kyle Fazzari (kyrofa) wrote :

Splitting the REST API into public/private sockets: https://github.com/snapcore/snapd/pull/1749

Revision history for this message
Kyle Fazzari (kyrofa) wrote :
Revision history for this message
Kyle Fazzari (kyrofa) wrote :

snapctl was the last of the generic hook machinery necessary for this feature, so setting to Fix Committed for snapd.

Changed in snapd (Ubuntu):
status: In Progress → Fix Committed
Changed in click-reviewers-tools:
status: New → Fix Committed
assignee: nobody → Jamie Strandboge (jdstrand)
Revision history for this message
Federico Gimenez (fgimenez) wrote :

Now that snap set is working and that configure hooks work it would be very useful to at least have the meta/hooks directory implicitly included in the snap, currently I need to do things like [1] and [2] (maybe there are better ways of doing that, please let me know if so).

Thanks!

[1] https://github.com/snapcore/spread-cron/blob/master/Makefile#L17
[2] https://github.com/snapcore/spread-cron/blob/master/snapcraft.yaml#L51

Revision history for this message
Kyle Fazzari (kyrofa) wrote :
Changed in snapcraft:
status: New → In Progress
Kyle Fazzari (kyrofa)
Changed in snapcraft:
status: In Progress → Triaged
Revision history for this message
Kyle Fazzari (kyrofa) wrote :
Changed in snapcraft:
status: Triaged → In Progress
assignee: nobody → Kyle Fazzari (kyrofa)
Changed in snapcraft:
status: In Progress → Fix Committed
milestone: none → next
Changed in snapcraft:
status: Fix Committed → Fix Released
Michael Vogt (mvo)
Changed in snapd (Ubuntu):
status: Fix Committed → Fix Released
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

The store has had this fix for some time.

Changed in click-reviewers-tools:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.