Hook: Run script when an interface is connected

Hey there,

I am currently working with snapcraft, interfaces and hooks. What I want to do is to provide datastorage with a data provider snap and I have some consumer snaps. The consumer snap has to create his own folders in the provider snap when the interface is connected.

In the hook documentation (https://docs.snapcraft.io/supported-snap-hooks/3795) you can read:

Or when an interface is connected or disconnected, the snap might need to obtain attributes specific to that connection. These types of situations are handled by hooks.

My problem now: I can´t find any hook that can do that. Is there something missing in the documentation?

Best regards

1 Like

this is (well, part of it):

which is still marked WIP…


…similiar to how “connect” hooks are implemented.

So as I understand there are already connect hooks available?

Yes, the documentation is incomplete unfortunately with that regard, but it will soon be updated as we’ve been reworking it a lot recently. Sorry about that.

The feature is already available. You can define the following hooks:

  1. On the snap that provides a slot:
  • prepare-slot-<slotname>
  • connect-slot-<slotname>
  • disconnect-slot-<slotname>
  • unprepare-slot-<slotname>
  1. On the snap that has a plug:
  • prepare-plug-<plugname>
  • connect-plug-<plugname>
  • disconnect-plug-<plugname>
  • unprepare-plug-<plugname>

From your description it looks like you want to do something in connect-* hooks. They are executed after the connection is made, when the new security profile is already in place.

I know this is not a perfect lecture, but you may take a look at our test snap used in automatic tests for some inspiration: