You are not logged in.

#1 2016-07-03 23:22:55

brandonio21
Member
Registered: 2014-09-24
Posts: 8

systemd Services Not Waiting for Network Connection

Hey guys,

So I have been banging my head against the wall for a while with this issue. I'm trying to have a systemd service that runs reflector on boot in order to update my pacman mirrorlist. However, the service always seems to run before a network connection exists. Here's reflector.service:

[Unit]
Description=Pacman mirrorlist update
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/reflector --protocol https --latest 30 --number 20 --sort rate --save /etc/pacman.d/mirrorlist

[Install]
RequiredBy=multi-user.target

The network-online target, to my knowledge, is triggered only by a netctl-auto hook, which looks as such:

#!/bin/sh
ExecUpPost="systemctl start network-online.target"
ExecDownPre="systemctl stop network-online.target"

When I start the system and login, reflector.service is already marked as failed, despite the fact that netctl-auto has not yet established a connection. Why isn't it waiting to run? Am I missing something here?

Last edited by brandonio21 (2016-07-03 23:27:05)

Offline

#2 2016-07-04 08:39:42

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,302

Re: systemd Services Not Waiting for Network Connection

With Wants= After= you have an optional dependency only.
Use Requires= After= instead to get a hard dependency:
see https://wiki.archlinux.org/index.php/Sy … pendencies

Offline

#3 2016-07-04 23:31:48

brandonio21
Member
Registered: 2014-09-24
Posts: 8

Re: systemd Services Not Waiting for Network Connection

You're right. I've changed the unit file to contain Requires, but alas, still not cigar.

It's quite perplexing because upon booting into the system, before the network is even connected, reflector.service is marked as failed. This leads me to believe that network-online.target is being started much before it should; however, I can find no evidence of this anywhere.

Offline

#4 2016-07-05 08:40:51

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,302

Re: systemd Services Not Waiting for Network Connection

The systemd journal should tell the starting sequence of the units.
Can you post it, beginning at the start of the systemd-journald service (the previous kernel lines are useless here).

Offline

#5 2016-07-07 05:08:02

brandonio21
Member
Registered: 2014-09-24
Posts: 8

Re: systemd Services Not Waiting for Network Connection

Thanks for all your help, berbae. After looking into the logs you suggested, I found that there was indeed something else starting network-online.target

In order to remedy my reflector situation, I made a new target, network-connected.target, and used netctl-auto's ExecUpPost to start it. However, this resulted in the same issue.

After struggling for quite some time, I've resolved to simply use a systemd timer to start all services that require an Internet connection and start them 1 minute after boot (While also forcing them to be "After" network-online.target).

Offline

#6 2016-07-14 23:37:43

thebombzen
Member
Registered: 2016-07-14
Posts: 6

Re: systemd Services Not Waiting for Network Connection

This sounds a bit like a silly question, but it appears, according to the article on netctl hooks, that the auto-hook you listed isn't there by default and you have to add it. That's what it seemed like from the article.

Offline

Board footer

Powered by FluxBB