5

I'm strying to make my systemd service start after internet connection has been established. I read several questions on this forum, but no success so far. The error is analog to Invalid host: somedomain.net

However, running sudo systemctl restart myservice.service does make the service run succesfully. I'm using Raspbian om my RPI 3 B+.

The myservice.service file:

[Unit]
Description=my_service
After=network-online.target

[Service]
Type=simple
User=pi
ExecStart=/home/pi/service_bash_script

[Install]
WantedBy=multi-user.target

What am I missing?

Thanks in advance!

edit1

The script is simple and requires connection to it create a UDP stream. It's something like:

   #!/bin/sh
   aisdispatcher -r -d /dev/ttyS0 -s 38400 -H 192.168.1.5:5001
DA--
  • 223
  • 2
  • 6

1 Answers1

6

network-online.target is a static unit. You can check it with:

rpi ~$ systemctl list-unit-files network-online.target
UNIT FILE             STATE
network-online.target static

1 unit files listed.

means it has no [Install] section and starts only if it is Wants or Requires by another unit. It cannot be started and stopped and does not run on bootup. But if it is not loaded then there is nothing to start After= and your unit will run without waiting for network-online. Add this statement:

Wants=network-online.target

to the [Unit] section and look if it fixes your problem.

Ingo
  • 42,961
  • 20
  • 87
  • 207