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
$ cat /etc/systemd/system/te-m-pi.service [Unit] Wants=network-online.target After=network-online.target [Service] Type=simple WorkingDirectory=/opt/te-m-pi ExecStart=/opt/te-m-pi/te-m-pi.py [Install] WantedBy=default.target
However when it's started it immediately quits because it can't resolve some host names it needs:
te-m-pi.py: socket.gaierror: [Errno -2] Name or service not known systemd: te-m-pi.service: main process exited, code=exited, status=1/FAILURE systemd: 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.