Ubuntu Snap Application API YAML

How do you configure the YAML for application API’s. For instance the snapcraft.YAML defined for Mosquitto does not define any API commands - and does not seem to work with mosquitto_sub or mosquitto_pub.

How do you configure the YAML for application API interfaces.


mosquitto.mosquitto_sub -h -t house/door -q 1 -d

mosquitto.mosquitto_pub -h -t house/door -m “knock knock” -d --cafile certs\ca.crt -p 8883 --insecure

Thanks in advance

I don’t understand what you mean by “configure for application APIs”. To add additional commands you just need to add another app config to the apps: section, and ensure the files are present in the snap by adjusting the prime: section to not exclude them. (at the moment the yaml only includes the usr/local/sbin/mosquitto file and dependent libraries, so you’ll need to add the mosquitto_sub and mosquitto_pub files wherever they reside.

Thank you Daniel. That helps.

By ‘configure for application APIs’ I mean ‘The snap application has public method interfaces to provide functionality. How are they made available in a deployed snap?’

I’m trying to get the https://github.com/eclipse/mosquitto/tree/master/snap to function on an Ubuntu 16 core
When I install Mosquitto in Ubuntu 17 with apt-get I can I can run

[user]$ mosquitto_pub -h -t house/door -m “knock knock”

from the command line. When the same code base is installed as a snap on Ubuntu 16, That doesn’t work.

I understand what you are saying about the apps:section and prime. I don’t know if Mosquitto_pub and Mosquitto_sub are separate packages. I know the client is. Good tip, I’ll look into that.

I’ve done the hello world tutorial. It doesn’t include an example where input values are passed. I believe that should be defined in a YAML Command entry. I’ve read most of the docs. I’m still not clear on how to configure YAML for an existing apt-get deployed app and have it function the same way with a snap deployed app.

I guess my real question should be, “why is the snap & YAML defined in https://github.com/eclipse/mosquitto/tree/master/snap incomplete?” or “Why don’t I understand how to make the snap version work like the apt-get version?”

I’ve got a bunch of apt-get to snap conversions to do for an IoT implementation using the appropriate Ubuntu 16 core platform on x86. .Not RPI/arm. I could use some help getting it clear in the brain.

Much thanks for the help.


Why, or How?

For “why”, whoever coded the snapcraft.yaml (if that wasn’t you) probably overlooked the other commands. If you coded it then “how” it is incomplete, I’ve already explained that the additional commands need to be specified and included.

Passing arguments to the command can be specified by the yaml if you want to ensure they’re always the same on every invocation. Otherwise omit them in the yaml and rely on the user entering them on the command-line when they call the apps.

All arguments passed by the user are forwarded into the command executed by snapd when running the app with no configuration required to make it so.

For example, you could specify an echo command on a snap called my-super-snap with command: echo foo.
It will always print out “foo” when called as my-super-snap.echo.
If the user calls your command with my-super-snap.echo bar then it will print “foo bar”.

In this way you can set arguments like “foo” in this example to always be passed, and the user can add their own arguments which supplement any hard-coded ones. You can also set the command with no arguments in the yaml and expect that the user pass them on the command-line.