Configure hooks to trigger the snap services after connecting non auto-connect interfaces

Hi Team,

For my snap , I need to connect interfaces manually and daemon must be started automatically once interface is configured. Interfaces are - system-observe,hardware-observe and network-control.

Method 1 : Configure-hook As per documentation, configure-hook is triggered when -

  1. initial installation
  2. snapctl set/get/unset
  3. refresh

Is there a way to trigger configure-hook when "snapctl refresh/start/stop $SNAP_NAME. " or "snapctl start --enable $SNAP_NAME. " is run ?

Method2 : Is there a way to automate the connection of manual-non auto connect interfaces ?

@ogra : I have gone through other posts on the same topic but its not working for me. So, I need your inputs here.

Current setup - . ├── hooks │ ├── configure │ ├── connect-plug-hardware-observe │ ├── connect-plug-network-control │ └── connect-plug-system-observe └── snapcraft.yaml

Once the interfaces are connected, the configure hook is not getting triggered.


Right, the configure hook is only executed on configure events coming from snapd or at package install time after the install hook …

I’d move the content of the configure hook into a separate script that you then can execute from the various hooks you want to call it from … (i.e. when the last interface is connected, call it from the interface hook)

To make sure that you only call it when the last interface hook is run, you will need some interaction between the interface hooks … here is an example where i am cross-checking between the hooks and make sure to only start my daemon once all hooks are connected:

(for your configure thingie i’d then simply put a line that runs the script mentioned above before the line that enables the daemon)

PS: and you indeed want your daemon packaged with install-mode: disable so it only starts after all hooks are connected

Yes thank you for the input. I have added install-mode: disable and have made changes. Yes its working .

I had another query -

Is there a way to automate and run script to connect non auto-connect interfaces when system boots up ?

1 Like

Autoconnect depends on the context…

If your snap is designed to run pre-installed on an UbuntuCore device you can set auto-connections on first boot via your gadget snap of the system or manage auto-connecttions on a per-snap basis via your brand store…

If you provide your snap via the global store to a wider user base you can file an auto-connection request here in the store-requests category… interfaces that are essential for the app to run might be considered for auto-connect if they are not actually super-privileged

Yes, snap is designed to run pre-installed on Ubuntu core and its private snap . And yes, the interfaces are not super-privileged. I figured out that for gadget snap , snap id is needed which is not available as it is not part of global store/brand-store. Is there a way to mention snap name instead of snap-id in gadget snap ?

Thanks, Shriya

The snap id is assigned to every snap by the store (no matter if it is a brand store or the global one) at its initial upload (and is permanent… i.e it never changes) … i dont think there is a way to use the name

Okay thanks for response. Currently, we do not have plans to upload to stores(global/brand).

Then only way is to configure it manually.