chr4

Devops. I've never asked for this.

Running rabbitmq on hosts with numeric hostnames

I encountered the following issue when running RabbitMQ on a host with the hostname 1.rabbitmq.staging:

1
2
3
4
5
6
$ sudo apt-get install rabbitmq-server
[...]
Job for rabbitmq-server.service failed because the control process exited with error code. See "systemctl status rabbitmq-server.service" and "journalctl -xe" for details.
invoke-rc.d: initscript rabbitmq-server, action "start" failed.
dpkg: error processing package rabbitmq-server (--configure):
 subprocess installed post-installation script returned error exit status 1

dmesg shows a segfault happened:

1
2
3
$ dmesg
[...]
[ 7891.350558] async_4[29072]: segfault at 0 ip 000000000055ff71 sp 00007f413997de40 error 4 in beam.smp[400000+234000]

When manually starting rabbitmq-server, I get the following message:

1
2
$ rabbitmq-server
ERROR: epmd error for host "1": badarg (unknown POSIX error)

The Bug

I found a bug report for the Ubuntu package rabbitmq-server, but as of today has no replies. Apparently, it’s not possible to run rabbitmq-server on a host that has a numeric hostname. I assume this is a bug in either Erlang or RabbitMQ and will eventually be fixed, hopefully.

RabbitMQ interprets everything after the first . in the hostname as domain, and therefore comes to the conclusion 1 is the full hostname.

The Workaround

The following workaround fixed it for me.

On Ubuntu, I added the following to /etc/rabbitmq/rabbitmq-env.conf:

1
2
3
4
5
# RabbitMQ cannot cope with hostnames containing only numbers.
# "1.rabbitmq.env" will be interpreted as hostname "1", and then fail.
# The workaround for this is manually adapting the HOSTNAME variable in rabbitmq-env.conf
# and making sure that it's resolvable in /etc/hosts
HOSTNAME=rabbitmq

Make sure to also add an entry for rabbitmq to your /etc/hosts file, otherwise rabbitmq-server will complain that it’s not resolvable:

1
2
# Resolve rabbitmq to 127.0.2.2, so we're not interferring with other localhost hostnames
127.0.2.2 rabbitmq

After that, starting rabbitmq-server works like a charm.

Note: Modifying HOSTNAME like this might cause other issues. I didn’t test it on clustered setups yet. Let me know if you know more!