Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting host name with Avahi fails #1287

Closed
majorz opened this issue Nov 14, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@majorz
Copy link
Contributor

commented Nov 14, 2018

Invoking the SetHostName method of the org.freedesktop.Avahi.Server interface on v2.26 does not succeed (and host name is changed over and over):

Nov 14 17:35:27 balena avahi-daemon[734]: Changing host name to 'aaaaaa'.
Nov 14 17:35:27 balena avahi-daemon[734]: Host name conflict, retrying with aaaaaa-2
Nov 14 17:35:28 balena avahi-daemon[734]: Host name conflict, retrying with aaaaaa-3
Nov 14 17:35:29 balena avahi-daemon[734]: Host name conflict, retrying with aaaaaa-4
...

Sample code for reproducing this (from a raspberrypi3-python container):

import dbus

iface = 'org.freedesktop.Avahi.Server'

host_name = 'aaaaaa'

bus = dbus.SystemBus()

avahi_object = bus.get_object('org.freedesktop.Avahi', '/')
avahi_server_iface = dbus.Interface(avahi_object, iface)

print(avahi_server_iface.GetHostName())

try:
    avahi_server_iface.SetHostName(host_name)
except dbus.exceptions.DBusException as err:
    if err.get_dbus_name() != "org.freedesktop.Avahi.NoChangeError":
        raise err

print(avahi_server_iface.GetHostName())

Front logo Front conversations

@majorz majorz changed the title Setting host name with Avahi Setting host name with Avahi fails Nov 14, 2018

@ZubairLK

This comment has been minimized.

Copy link
Collaborator

commented Nov 22, 2018

@majorz @agherzan I think we are hitting an avahi bug here. lathiat/avahi#117

tl;dr. Avahi broadcasts SetHostName on multiple interfaces and basically confuses itself. Thinking the hostname is already assigned and thus conflict.

If I edit /etc/avahi/avahi-daemon.conf with allow-interfaces=enp0s3, I can set the hostname.

This is a tricky one.. As we probably need Avahi in the container interfaces to work.

Has anyone tried to set the hostname via org.freedesktop.hostname1 ?

@ZubairLK

This comment has been minimized.

Copy link
Collaborator

commented Nov 22, 2018

We can use hostname1 provided by systemd

dbus-send --system  --print-reply  --dest=org.freedesktop.hostname1 /org/freedesktop/hostname1 org.freedesktop.hostname1.SetHostname  string:"helloworld2" boolean:true
root@balena:~# hostnamectl 
   Static hostname: test
Transient hostname: helloworld2
         Icon name: computer-vm
           Chassis: vm
        Machine ID: de9f101eeeb2498cb08ecf9d5428f81c
           Boot ID: 0e1b1869ddb54d3db47356ffc2e2f7fa
    Virtualization: oracle
  Operating System: balenaOS 2.24.0+rev3
            Kernel: Linux 4.14.48-yocto-standard
      Architecture: x86-64
root@balena:~# cat /etc/hostname 
test
root@balena:~# hostname
helloworld2
@agherzan

This comment has been minimized.

Copy link
Member

commented Nov 22, 2018

We expose the hostname via config.json as well. @majorz wouldn't that be good for a workaround?

@majorz

This comment has been minimized.

Copy link
Contributor Author

commented Dec 4, 2018

There are two workarounds for the Avahi bug until there is a fix from the Avahi maintainers:

  1. Do not change the host name with Avahi, but use the AddAddress of the org.freedesktop.Avahi.EntryGroup instead. It is important to use the no reverse flag when using that, since it will lead to another Avahi bug.

  2. If host name really should be changed through Avahi, then first the host name needs to be changed though our supervisor API, then the Avahi daemon should be restarted through the systemd D-Bus API, so that it can pick up the changed host name.

@ZubairLK

This comment has been minimized.

Copy link
Collaborator

commented Jan 22, 2019

The thread seems to have reached a conclusion with suitable workarounds.
I don't see anything that can be done via meta-balena.

Closing the issue for cleanup.

@ZubairLK ZubairLK closed this Jan 22, 2019

@mdtusz

This comment has been minimized.

Copy link

commented Mar 28, 2019

@majorz could you elaborate a bit on setting the hostname address using AddAddress and the no-reverse flag part specifically? There's no formal documentation for usage of avahi with DBus (or at least none I could find) and I can't find any reference to a no-reverse flag either. Setting the hostname using the supervisor seems to have the same issues with a continually incrementing suffix on the hostname/address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.