Best practices for hooks


I recently added some hooks to Juju, the required action is the same for both the hooks so I created a script and symlinked install and post-refresh to it.

This gave me a couple of issues when trying to upload to the store, issues that weren’t flagged by snapcraft on build so where a surprise to me.

First issue was an unknown hook file in snap/hooks/ (in this case the script that I wrote and symlinked to).
I went to rectify this (as I didn’t want to have to review that any timed we changed it) so that the script file lived outside of the hooks dir (snap/local, which gets dumped) but now I get failures as the install and post-refresh hooks aren’t executable (the script they are linked to is though) and everything works when I use snapcraft to build it and install/test it in a fresh lxd container.

Does this mean that the best thing I can do that the store will be happy with is have 2 identical scripts in the hooks dir or is there something better I can do?

I wasn’t able to see any details around this in these docs nor in a search of this forum here.


We have a similar requirement, and have hooks/configure as the canonical source, with hooks/refresh symlinked to that, both are chmod +x'd


Ah, a nice way to do it (and so obvious in hindsight :-)). Thanks @sparkiegeek!


Oh, so the symlink doesn’t throw an error in the store? Perhaps I’m doing something wrong then.


Can I invite you to test Call for testing: snapcraft 3.3 which allows you to, among other things, set “base: core” and for the right thing to happen.

Feedback is welcome, launchpad builders are setup to do the right thing when “base: core” is found in your snapcraft.yaml