Balena Supervisor & Avahi

Hello,

it seems that in the latest versions of the balena OS the supervisor is using Avahi on the host OS. If one has a multi container project, I understand that they do not need avahi in the container but they can somehow tell the supervisor about the services they launch. I have seen the zoo publisher but this creates a static service file, what if the software I run in the containers already supports avahi? Can I not take advantage of that?

I wish there was a single variable that could instruct the supervisor to publish ports for each container to avahi, anyone has tried anything similar?

Hey @krital,

I’d like to understand a little better what you are trying to achieve and then work through it with you :slight_smile:

So all balena devices will advertise themselves as <short-uuid>.local. This will obviously just resolve to the device’s local address.

Now this means that any ports you expose (using the docker-compose expose or ports fields) should be accessible over this address.

Does this clear things up for you? If not understanding exactly what you’re trying to do would be helpful.

Hi Cameron,

thanks for the response. I have a multi container project running on a balena fin 1.0 where several of the containers should expose services over MDNS / Avahi. So far:

  1. The host id.local is advertised by host os
  2. The zoo publisher example also advertises its services. However it using SystemD and creates an avahi service file.
  3. I have a node js application that uses the mdns npm module but it exposes programmatically its services and has no systemd.

What seems to happen is that I can see all service definitions in the subnet (using Discovery on a Mac) but the ones from the container on item 3 above have 0 items.

Do I have to mimic the zoo example or can I somehow programmatically tell the avahi daemon about these services?

Thanks in advance,

Alex Kritikos

Hey @krital, I see what you mean now. I think what’s probably best is if I reach out to @hedss about this, as he wrote the zoo publisher example and has a bunch of experience working with avahi, so if anybody knows it would be him.

He’s currently on time off, ending tomorrow, so he should be able to reply in the next day or two. Until then it might be worth posting the code you’re using for a reference.

Hi @krital ,

There’s definitely a way to programmatically publish and withdraw services.

I’ve never used the mdns NPM module, but it does look like it relies on avahi-daemon running to operate, which means you’d need it in your container and using host networking (this won’t work over the Docker bridge). Did you enable host networking for the service publishing the services?

An alternative would be to hook into the host instance of Avahi using DBus from within your service, and then use this to publish/withdraw services as required. I haven’t actually got an example using services, but we have created something similar to publish hostnames in the following project: https://github.com/balena-io/balena-mdns-publisher
https://github.com/balena-io/balena-mdns-publisher/blob/master/src/app.ts shows how we use a DBus NPM module in TypeScript to communicate with the underlying host OS Avahi instance to publish hostnames. However, the DBus API for service publishing is very similar and you should be able to swap out the call to AddAddress with AddService with relevant parameters for this to work (and similarly for withdrawing services).

I have just found a quick Python example here: https://stackoverflow.com/questions/1534655/creating-a-program-to-be-broadcasted-by-avahi so you should be able to use the same parameter list.

Best regards, Heds

Thanks very much for this I will definitely give it a try!