Add support for hooks
Metadata
Current evaluation
Hook support was added in snapcore/snapcraft#1026 via commit 01880ee8d, packaging hook files and snapcraft.yaml hook definitions.
Resolution: closed resolved
Reason: The feature was implemented by the merged PR snapcore/snapcraft#1026, recorded in commit 01880ee8d as "core: add support for hooks."
Evaluated by: mr-cal-bot
No scores available.
Issue body
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.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Hook support was added in snapcore/snapcraft#1026 via commit 01880ee8d, packaging hook files and snapcraft.yaml hook definitions. | |
| stealth/space-bunny-alpha | — | closed resolved | Hook support landed in snapd through multiple PRs, including YAML parsing (#1240), hook execution (#1511), and snapctl communication (#1718); the maintainer marked it Fix Committed. | |
| stealth/space-bunny-alpha | — | closed resolved | Implemented hook packaging in merged PR canonical/snapcraft#1026 (commit 01880ee8d), with executables from snap/hooks/ and parts; PR #1042 added documentation. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed without discussion or implementation. The proposal for snapd hooks was likely abandoned or superseded by later snapd features. No merge or resolution details were recorded. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed without implementation. The feature request to add snap.yaml hooks support was abandoned or superseded by subsequent snapd developments. | |
| qwen/qwen3.6-35b-a3b | — | — | Proposed adding a hooks section to snap.yaml for snapd event notifications and upgrade migrations. Closed after over nine years with zero comments and no resolution, indicating the feature request was abandoned or superseded. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Closed without implementation. The snapd hooks proposal was abandoned due to lack of discussion and no subsequent merge or resolution. |
Update history
| Date | Change |
|---|---|
| created |
Related work
-
Likely Fixed By:
snapcore/snapcraft#1026
(confidence 100%)
Merged implementation adding Snapcraft support for hooks.
-
Related To:
snapcore/snapcraft#921
(confidence 90%)
Earlier Snapcraft hooks implementation attempt referenced in the issue before #1026.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #3659 meta: add support for hooks | snapcraft | merged | Merged snapcraft#3659 via commit 00eed7dc9 (merge 795294fd5) into snapcraft/7.0, adding hooks support in snapcraft.yaml for CRAFT-808. | |
| #1026 Add support for hooks. | snapcraft | merged | PR #1026 merged as commit 01880ee8d ('core: add support for hooks'), adding hook support: executables in snap/hooks/ are copied into the snap, and parts can install hooks into snap/hooks/. Docs followed in #1042 (10c58b652). | |
| #921 Add support for hooks. | snapcraft | closed | PR #921 (declarative `hooks:` with generated hook scripts) was closed unmerged after redesign discussion with snapd's niemeyer; hook support instead landed in #1026 (commit 01880ee8d) with docs in #1042. | |
| #3565 schema: add environment support for hooks (CRAFT-424) | snapcraft | merged | Merged PR snapcore/snapcraft#3565, adding CRAFT-424 hook environment support, shared schema definitions, snap metadata processing, and unit/spread tests. | |
| #1797468 Add support for hook command-chains | snapcraft (launchpad) | closed | Hook command-chain support shipped in canonical/snapcraft#2850 (41c9fb464); LP #1797468 was later closed as stale after nearly eight years. | |
| #4592 Support project hooks for core24 snaps | snapcraft | closed | Core24 project hook packaging was implemented in snapcraft#4717 and merged as commit aafbe672b, with hook-packaging tests. | |
| #1980089 Compiled snap hooks not executed when packaging with Snapcraft 7 | snapcraft (launchpad) | closed | Compiled snap hooks are supported again by merged PR snapcore/snapcraft#3837 (commit c77e3a07a), which processes generated hooks and restores the expected meta/hooks entries. | |
| #3837 fix: hooks: process generated hooks | snapcraft | merged | Merged as commit c77e3a07a (CRAFT-1159): core22 now includes lifecycle-generated hooks in the snap via meta/hooks wrappers, with snap/hooks taking priority; adds spread tests for core18/20/22. | |
| #1042 Add documentation for hooks. | snapcraft | merged | Merged as commit 10c58b652, adding hook usage documentation and completing the Snapcraft portion of Launchpad bug #1586465. | |
| #1812003 hooks should be made executable instead of erroring out | snapcraft (launchpad) | closed | Fixed by merged PR snapcore/snapcraft#2440 (commit c2f5a0dc0), which packages recognized hooks as executable instead of rejecting non-executable source files. |