Uplink socket.gaierror from systemd service

What I’m trying to do:
I want to start a script on boot that uses Uplink from systemd on a raspberry pi4. The script runs normally when called manually but systemd could not run it successfully. It always errors out on: socket.gaierror: [Errno -3] Temporary failure in name resolution. Any help would be appreciated.

What I’ve tried and what’s not working:
I have searched on linux and raspberry pi forums where I got the hint to look through /var/log/syslog. I saw that the problem arises when connection is to be made with the anvil server at anvil.server.connect(“xxxxx-xxxxx-CLIENT”). Here is my unit file:

[Unit]
Description=description…
After=network-online.target

[Service]
Type=idle
ExecStart=python3 -u uplink_script.py

[Install]
WantedBy=network-online.target

Code Sample:

# this is a formatted code snippet.
# paste your code between ``` 

Clone link:
share a copy of your app

This sounds too easy, but have you tried introducing a delay in your script of 5-10 seconds before connecting to anvil?
This would give your pi some time to finish sorting its network drivers before attempting to use them.

Also in the past I have also used crontab to run scripts, telling it to start every 1-5 minutes or so, and then having the script manage the number of instances allowed.
Essentially it just parses the output of the linux command ‘ps aux’ and looks to see if the specific script is already running, (running twice, since it itself is running) and if so, just exits instead of running a script that should be running forever.
That would be a second method to do what you want. FYI, by default crontab runs as root so be mindful of this.

3 Likes

I followed your advice and it worked perfectly. I had hoped that putting After=network-online.target in my unit file would have ensured there’s an internet connection before running the uplink script but it seems that wasn’t sufficient. Many thanks!

1 Like