Snapcraft supports snapd’s hooks mechanism using two possible methods:
snap/hooks/directory in the root of the project and place hook executables in there. They will automatically be copied into the snap during the
primestep. Note that these hooks will not be influenced by parts (e.g. no
$PYTHONPATHwill be defined, even if the snap includes a python part). A demo is available that shows this feature.
Install hook executables from parts into
$SNAPCRAFT_PART_INSTALL/snap/hooks/. These will automatically be copied into the snap during the
primestep, and wrappers will be generated for them to include the part’s environment (e.g.
$PYTHONPATHwill be defined). A demo is available that shows this feature.
As long as the file name of the executable corresponds to a hook name supported
by snapd, that’s all one needs to do in order to utilize a hook within their
snap. Note that hooks, like apps, are executed within a confined environment. By
default hooks will run with no plugs; if a hook needs more privileges one can
use the top-level attribute
snapcraft.yaml to request plugs, like
hooks: # Top-level YAML attribute, parallel to `apps` configure: # Hook name, corresponds to executable name plugs: [network] # Or any other plugs required by this hook
Note that hooks will be called with no parameters. If they need more information
from snapd (or need to provide information to snapd) they can utilize the
snapctl command (for more information on