collectd: FQDNLookup prevents starting on boot
I have found that collectd fails to start on boot, and that the daemon prints the following error message:
Looking up "[HOSTNAME]" failed. You have set the "FQDNLookup" option, but I cannot resolve my hostname to a fully qualified domain name. Please fix the network configuration.
I tried to address this by adding the following to /etc/init.d/collectd
:
depend() {
need net
after firewall
after hostname
}
This did not fix the problem. I did add this kludge to the definition of start_pre
, and it fixed the problem:
sleep 20
Clearly this is not the correct solution, but it seems to indicate something is otherwise not finishing before collectd starts. I wonder if it is the initialization of IPv6, which can take a few seconds, but I have not yet found evidence of this. The relevant code in collectd, which seems to be detecting and printing the error is in src/daemon/collectd.c
:
char hostname[hostname_len];
if (gethostname(hostname, hostname_len) != 0) {
fprintf(stderr, "`gethostname' failed and no "
"hostname was configured.\n");
return -1;
}
hostname_set(hostname);
str = global_option_get("FQDNLookup");
if (IS_FALSE(str))
return 0;
struct addrinfo *ai_list;
struct addrinfo ai_hints = {.ai_flags = AI_CANONNAME};
int status = getaddrinfo(hostname, NULL, &ai_hints, &ai_list);
if (status != 0) {
ERROR("Looking up \"%s\" failed. You have set the "
"\"FQDNLookup\" option, but I cannot resolve "
"my hostname to a fully qualified domain "
"name. Please fix the network "
"configuration.",
hostname);
return -1;
}