problems with network-online-target dependency in systemd

I am trying to:

  • run a bash script on booting Kubuntu (Ubuntu 19.10)
  • after my internet connection is established
  • using systemd (using the network-online.target service)

I wrote the .service file below. It refers to an sh executable that tests if IPv4 is up via ping.

  • The script (which is executable by all) works, it tells me I'm up when I run it manually.
  • Systemd calls the script successfully on boot, I can see the script has run after booting

However, somehow systemd calls my service before my internet connection is up while it should wait for the internet connection before running. Anybody any idea what is going wrong here? See code below:

My script (/home/me/scripts/testInternetConnection.sh):

if ping -q -c 1 -W 1 8.8.8.8 >/dev/null; then echo "IPv4 is up" >> /home/me/Desktop/result.txt
else echo "IPv4 is down" >> /home/me/Desktop/result.txt
fi

My service file definition (/etc/systemd/system/myConnectionTester.service):

[Unit]
Description=test internet connection
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=me
WorkingDirectory=/home/me
ExecStart=/home/me/scripts/testInternetConnection.sh
[Install]
WantedBy=multi-user.target
WantedBy=network-online.service

Thanks in advance!

N.

5 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like