pianod, a Pandora client/server, on a Raspberry Pi with Arch Linux ARM. I have
pianod set up to run as a service at boot. It starts up before the network stack, so
getaddrinfo() fails. This should be okay;
pianod is setup to retry network login every 60 seconds.
(Aside: I tried obvious things to get
systemd to wait for the network stack before starting
pianod, but it wasn't working. On the
systemd list, I was advised that really I should just try to make my process behave well if network isn't available, a perspective I can appreciate. There are other hacks to make my process sleep during boot, etc.. I'd be interested if there is such a hack that's actually standard for some reason, but would prefer a clean solution.)
pianod retrying network every 60 seconds after initial fail on boot,
getaddrinfo() persists in returning
EAI_NONAME. If I restart the process manually everything works.
The issue seems to be that on the first call to
getaddrinfo() on boot,
res_init() is called and tries to load
/etc/resolv.conf. Since DHCP hasn't initialized that file with proper DNS information yet (?), this loads bad DNS (localhost I think) information into the process's global
_res variable. The process is then stuck with
Adding a manual re-call to
res_init() to reload DNS info after failed
getaddrinfo() calls makes the thing work, i.e.
getaddrinfo() succeeds on the first login retry 60 s after boot.
BUT... I'm pretty surprised that this is an issue. I have another service that does essentially the same thing and doesn't seem to need the manual
res_init(). The other process does a bit more
fork(), but I don't see where it would escape from the bad
_res global. In general I'm surprised Linux is setup to have this issue.
So I felt like I should ask around what I might be missing here. Does my interpretation sound correct? If so, why is this not handled better upstream? If not, what more should I look into? Are there better standard ways to handle this?
UPDATE: as requested, here's the current service unit description.
I have tried adding
After=network.target as well as
Requires. From what the
systemd folks said, these aren't reliable from one distro to the next...
[Unit] Description=Pandora Client Daemon After=syslog.target [Service] EnvironmentFile=/etc/pianod.env ExecStart=/usr/sbin/pianod $INITSCRIPT $USERFILE $PORT $LOGGING -nroot Restart=on-abort [Install] WantedBy=multi-user.target