I've got a program that I want to start by systemd on boot but only after DNS is available.

The service file depends on network-online.target:

$ cat  /etc/systemd/system/te-m-pi.service



However when it's started it immediately quits because it can't resolve some host names it needs:

te-m-pi.py[399]: socket.gaierror: [Errno -2] Name or service not known
systemd[1]: te-m-pi.service: main process exited, code=exited, status=1/FAILURE
systemd[1]: Unit te-m-pi.service entered failed state.

If I edit the python file and insert a simple time.sleep(10) at the very beginning it waits 10 seconds and then happily runs as it should.

Apparently when it's started the network is not yet available, despite the dependency on network-online.target. How can I make sure that it's only started when the network is really really up and configured?

I'm running it on Raspbian 8 Jessie with systemd 215-17+deb8u7.

  • Are you using NetworkManager or something? Could you check is you have anything in /etc/systemd/system/network-online.target.wants/ ? – Bigon Jul 18 '17 at 6:11
  • @Bigon I don't think I'm using Network Manager. I don't have any network-online.target.wants dirs anywhere on the system (checked /etc, /usr and /var). Perhaps network-online returns before dhcpcd is finished? But what's the point of network-online then... – MLu Jul 18 '17 at 6:22
  • In jessie I think that the ifupdown package is not really well integrated systemd, you should try to update to the backported version of it (version 0.8.13~bpo8+1). Not sure how to do that with raspbian. The easiest would be to upgrade to stretch I would say – Bigon Jul 18 '17 at 6:50
  • Thanks @Bigon I will try with the newest Raspbian and see if it's any better. – MLu Jul 19 '17 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.