You are not logged in.

#1 2021-04-27 09:03:53

justasug
Member
Registered: 2014-08-03
Posts: 174

[SOLVED] Service fails because of DNS lookup

I have a simple Python script that fetches a website and it's being started via a systemd user service. The service fails because it's being started up before the network/DNS resolution is up. Here is the error message:

× bms_update.service - Check for Falcon BMS updates
     Loaded: loaded (/home/dino/.config/systemd/user/bms_update.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2021-04-27 10:36:25 CEST; 9min ago
    Process: 910 ExecStart=/usr/bin/bms_update.py (code=exited, status=1/FAILURE)
   Main PID: 910 (code=exited, status=1/FAILURE)
        CPU: 296ms

Apr 27 10:36:25 masina-l bms_update.py[910]:     result = self._call_chain(self.handle_open, protocol, protocol +
Apr 27 10:36:25 masina-l bms_update.py[910]:   File "/usr/lib/python3.9/urllib/request.py", line 494, in _call_chain
Apr 27 10:36:25 masina-l bms_update.py[910]:     result = func(*args)
Apr 27 10:36:25 masina-l bms_update.py[910]:   File "/usr/lib/python3.9/urllib/request.py", line 1389, in https_open
Apr 27 10:36:25 masina-l bms_update.py[910]:     return self.do_open(http.client.HTTPSConnection, req,
Apr 27 10:36:25 masina-l bms_update.py[910]:   File "/usr/lib/python3.9/urllib/request.py", line 1349, in do_open
Apr 27 10:36:25 masina-l bms_update.py[910]:     raise URLError(err)
Apr 27 10:36:25 masina-l bms_update.py[910]: urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>
Apr 27 10:36:25 masina-l systemd[836]: bms_update.service: Main process exited, code=exited, status=1/FAILURE
Apr 27 10:36:25 masina-l systemd[836]: bms_update.service: Failed with result 'exit-code'.

Here is my service file:

[Unit]
Description=Check for Falcon BMS updates
Wants=network-online.target
After=network-online.target nss-lookup.target

[Service]
Type=simple
ExecStart=/usr/bin/bms_update.py

[Install]
WantedBy=user-graphical.target

I have looked at the relevant systemd Wiki page and adjusted my service file. I added the nss-lookup.target as seen above, but I'm still getting the error above. I assume it's because nothing is pulling in that target as mentioned on that page.

$ systemctl list-dependencies --reverse nss-lookup.target
nss-lookup.target

My question is: do I have to install one of those DNS resolvers for that to work or is there another way? I understand that installing it would most likely solve it, but I am reluctant since my setup is already working and I am trying to see if I can make this work without an additional package. The DNS resolving is handled in my case by Network Manager I assume (as mentioned by the comment in /etc/resolv.conf). Is there a way to make Network Manager signal that DNS resolving is working?

$ cat /etc/resolv.conf

# Generated by NetworkManager
search hitronhub.home
nameserver 192.168.1.1
nameserver 2a02:810d:abbf:f924::1

Last edited by justasug (2021-04-28 16:58:47)

Offline

#2 2021-04-27 09:09:30

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,337

Re: [SOLVED] Service fails because of DNS lookup

You can't depend on system targets from a user instance service.

Depending on what your exact intention is here you might be able to use a system service that depends on network-online.target and just use User= to run the thing as your user. Or just manually call nm-online as part of your script/ExecStartPre=

Last edited by V1del (2021-04-27 09:17:10)

Offline

#3 2021-04-28 16:58:31

justasug
Member
Registered: 2014-08-03
Posts: 174

Re: [SOLVED] Service fails because of DNS lookup

Thanks for the tip. I didn't know about the system/user separation.

I settled for calling nm-online from inside the script. I couldn't do it the system service way because the script displays GUI notifications and I assume it wouldn't work if it's started before my X session.

Offline

Board footer

Powered by FluxBB