Install and remove hooks

The release 2.27 of snapd introduced support for two new hooks: install and remove.

  1. The install hook can implement any custom initialization logic and it gets executed (if present in meta/hooks/install) when the snap is installed for the first time (contrary to configure hook, which gets executed every time a new revision of the snap gets installed). Install hook runs before any services shipped with the snap are started and before configure hook. This gives the snap a chance of doing any early initialization when installed for the first time.
    Note: clearly install hook doesn’t help with snap updates (refreshes), this will be covered by another hook type which is coming with future snapd release.
  2. The remove hook can implement any custom cleanup logic. It is executed (if present in meta/hooks/remove) when the last revision of the snap gets removed from the system. Remove hook runs after any services provided by the snap are stopped but before any data provided by the snap is cleaned up by snapd.

Both hooks run confined under the confinement of their snap (unless defined explicitely in snap.yaml with specific plugs, in which case they may be granted extra permissions of these plugs as long as they’re auto-connected).

1 Like

@pstolowski could you update too?

For what it’s worth, I filed a bug against the tutorials site since that also needs to document these new hooks. It wouldn’t surprise me if there are other parts of the snappy world that need updating too. :neutral_face:

This wiki is being updated litearally now :slight_smile: by @davidcalle, expect it soon.

1 Like

Actually… I confused the wikis… We have more than one and the one @davidcalle updated looked identical to snapd’s one with regard to hooks, that’s why I confused them. So, David updated so your bug report remains valid…
EDIT: his updated is not yet live, but will be soon.

@kyrofa’s blog post about the install hook could easily be transformed into a tutorial.

@pstolowski The general hooks documentation is now here in the forum.

When you have a moment, would you mind to document any hooks missing there?

Thanks, sure, will do.