hashicorp / consul

Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
https://www.consul.io
Other
28.39k stars 4.43k forks source link

Resolve localhost on start, or specify localhost address in config. #5133

Open alexander-n-lunev opened 5 years ago

alexander-n-lunev commented 5 years ago

Feature Description

Initial resolve of localhost address, or a way to specify localhost address in config.

Use Case(s)

On FreeBSD there is no 127.0.0.1 address in jails. A common practice is to give jails 127.0.0.2, 127.0.0.3 and so on addresses for their lo0 interface and specify that address in /etc/hosts as localhost, then every service that bind to localhost will resolve correct address.

IP 127.0.0.1 is hardcoded everywhere in consul sources, and because of that consul won't start in FreeBSD jail.

pearkes commented 5 years ago

127.0.0.1 is often a default in Consul but I think you can avoid this by just specifying the appropriate address for each configuration item and then not use that hardcoded default. Are you thinking of an additional configuration item to define that default instead of individually overriding client_addr and so on?

alexander-n-lunev commented 5 years ago

Yes, something like "local_addr" will do.

Right now consul won't start in FreeBSD jail with localhost address = 127.0.0.2. Is it possible to run current consul on that configuration?

pearkes commented 5 years ago

@alexander-n-lunev All the addresses are configurable and can be overridden independently unless I'm missing something so yes, it should be possible! See here for more: https://www.consul.io/docs/agent/options.html#addresses.

alexander-n-lunev commented 5 years ago

Oh, now i see why it couldn't run in jail (should've start it by hand earlier, FreeBSD starting script is hiding what consul's complains): consul can't connect to jailed syslogd via UDP (though it's listening on *:514), and if i understand it correctly, then it tries to open unix socket, and there are two hardcoded paths to sockets in go-syslog package, which are both not match to FreeBSD' syslogd' socket path, it's in /var/run/log (and in go-syslog package it's logPaths := []string{"/dev/log", "/var/run/syslog"} in builtin.go).

So it's an issue about syslog connection to jailed syslogd, and not about localhost resolving. Or maybe it could be solved by specifying path to syslogd socket in config file?