Supported snap hooks

This page seems to be missing any mention of the “check-health” hook.

This is because the feature isn’t yet fully implemented (see Health Checks). While some parts do work, such as using snapctl set-health and the health status appearing in the output from snap info, I don’t think the store yet has the functionality to process any health status. This is why we’ve held off documenting this fully and the hook specifically.

The explanation of install-device hook versus prepare-device hook seems confusing. install-device hook is described as supported only in UC20 gadget snaps, while prepare-device claims only in gadget snaps (not just UC20? is that deliberate?).

In addition, even though both hooks are defined in the gadget snap, for install-device, you’re referred to the “Installation process” page, while for prepare-device, you’re sent to “The gadget snap” page. This seems unnecessarily scattered; why are these two apparently related hooks not explained in the same place?

How do I access previous state of the snap from post-refresh hook? $SNAP will give me the current state but I want to access the state before the refresh and compare a file between the 2 states.

Another glaring omission is any mention of command-chain usage (which is supported) for hooks. It probably belongs on this page, unless it makes more sense to add to the main snapcraft yaml referrence page.

There is apparently a “check-health” hook that I only now just noticed. https://github.com/snapcore/snapd/blob/master/snap/hooktypes.go#L38

@degville this doc mentions that configure hooks that exit non-zero prevent an install of the respective snap (or cause a rollback) this is actually true for all hooks involved in any interface autoconnection too, not only for configure or default-config … could we have a paragraph or note on this ?

Thanks for letting me know, and yes of course. I’ll make sure one is added (and reply here when it’s done).

Update 6th July 2023: I just added the auto-interface rollback details. Thanks for the suggestion!

If the main purpose of the default-configure hook is to get access to the default config info in the gadget snap, should it not be run again if the gadget snap is updated? After all, updating the gadget snap could change that config info.

This section https://snapcraft.io/docs/supported-snap-hooks#heading--the-configure-hook claims that the configure hook is called under three circumstances, but I’m fairly sure it’s also called via the appropriate snapd REST API call, no? Can you confirm that?

You mean the equivalent API call for, eg., refresh? I’m certain this is the case, yes. If this is what you mean, I’ll tweak the text to make it clearer.

Yup, this: Snapd REST API

Should this indicate that the configure hook is run before services start?

The following mentions that both starting services and the configure hook run after the install hook, so the absence of anything explicit in the configure hook is suggestive that there is no guarantee whether configure or services run first.