Where to create target layout directories

Dear all,

I am trying to use the azure iotedge snap and it seems to have issues with the layout. That is, when I try to configure the package it complains about certain paths not existing:

Command failed: could not create /etc/aziot/config.toml
Caused by:
    No such file or directory (os error 2)

In the snapcraft file I see that the snap has this layout:

    symlink: $SNAP_COMMON/var/lib/aziot
    symlink: $SNAP_COMMON/var/lib/iotedge
    symlink: $SNAP_COMMON/shared/sockets/aziot
    symlink: $SNAP_COMMON/shared/secrets/aziot
    symlink: $SNAP_COMMON/shared/config/aziot
    symlink: $SNAP/usr/libexec/aziot/aziot-edged
    symlink: $SNAP/docker/config/daemon.json

However, I think the target directory is never created, because its a symlink (copied from your docs):

If <source-path> and <target-path> don’t already exist, they will be automatically created by snapd. This includes the creation of new empty files, but doesn’t include the creation of symbolic link targets. This is because snapd doesn’t know what kind of objects they may eventually point to. In the previous example, $SNAP_DATA/etc/foo.conf is created before any snap application code is executed.

Question 1: Where would be the correct location to create the target-path’s this snap needs?

Question 2: I see in your documentation layouts are “transparently supported” from base core22, but the snap that is using this has core20… Will it still work?

The location is fine, the directory structure should be creatdd from the install hook (IIRC symlink layouts do not create the target dir structure while bind and bind-file ones do) … (you will also find the install hook has slightly broken code that tries to create these dirs in differnt locations already, at least that is what i vaguely remember from looking at it last time, this will need some cleanup)

I dont thonk layout behavior has changed a lot between core20 and 22 so it should be fine…

1 Like

What is the easiest way to debug the install hook?

I am trying with snapcraft -v try and sudo snap try prime but I have the feeling it is not running (again)? I might be wrong. Still getting used to the locations of $SNAP_COMMON when installing a snap and doing snap try.

That is, when I log $SNAP_COMMON from inside my app I print /var/snap/azure-iot-edge/common/ but when I am trying to add anything to this folder in my install hook I don’t see anything added to this directory (when doing .

More detailed:

I added

echo "foo" > $SNAP_COMMON/foobar
echo "Bla" > $SNAP_COMMON/var/log/foo.log

inside snap/hooks/install

I then rerun snapcraft try and sudo snap try prime, but then both of these find command return nothing:

~/iotedge$ find /var/snap/azure-iot-edge/ -name foo.log
~/iotedge$ find -name foo.log

The same when I do snapcraft and an install through sudo snap install azure-iot-edge_1.4.0~dev_amd64.snap.

FYI, I saw that the install hook is not listed in the snapcraft.yml:

      - aziotctl-executables
      - docker
      - hostname-control
      - identity-service
      - log-observe
      - mount-observe

Could that be the reason its not running?

Ok I see.

I have to add it to the install hook, and to rerun the install hook I have to remove and install the snap package.

Is there any way to trigger it in the ‘try’ mode?

I found some useful information about seeing what hooks run etc here: https://snapcraft.io/blog/snap-install-time-setup-the-install-hook

1 Like

I found I gen trigger the install as follows:

sudo snap run --hook install azure-iot-edge

That is very helpful :slight_smile:

I also find I don’t have to rerun snapcraft try, but I can edit prime/meta/hooks/install directly (ofcourse, if I do snapcraft try after it will overwrite this file).

I also found that although some of the folders needed are in prime/etc in the install stage the files are written to /var/snap/azure-iot-edge/..., and this is what the application uses. This makes sense now (was just confusing at first, I thought everything would be in prime).

I am still struggling to find out how to give the app permissions to make a new file. I get a permissions error. I am assuming I am missing a plug, but I got the plugs defined as:

    interface: content
    content: aziotctl-executables
    target: $SNAP/aziotctl
    interface: content
    content: docker-executables
    target: $SNAP/docker
    interface: content
    content: aziot-identity-service
    target: $SNAP_COMMON
    interface: system-files
      - /var/run/iotedge
      - /run/iotedge
      - /etc/aziot

and the app has plugs

    command: usr/bin/iotedge
      - docker
      - identity-service
      - home
      - log-observe
      - mount-observe
      - network
      - system-observe
      - run-iotedge

So I don’t know why it is not allowed to create a file in /etc/aziot (which points to /var/snap/azure-iot-edge/common/shared/config/aziot)

I did connect the plugs:

$ snap connections azure-iot-edge
Interface         Plug                                 Slot               Notes
content           azure-iot-edge:aziotctl-executables  -                  -
content           azure-iot-edge:docker-executables    -                  -
content           azure-iot-edge:identity-service      -                  -
docker            azure-iot-edge:docker                -                  -
home              azure-iot-edge:home                  :home              -
hostname-control  azure-iot-edge:hostname-control      :hostname-control  manual
log-observe       azure-iot-edge:log-observe           :log-observe       manual
mount-observe     azure-iot-edge:mount-observe         :mount-observe     manual
network           azure-iot-edge:network               :network           -
network-bind      azure-iot-edge:network-bind          :network-bind      -
system-files      azure-iot-edge:run-iotedge           :system-files      manual
system-observe    azure-iot-edge:system-observe        :system-observe    manual