You are not logged in.
Hi!
I have a Systemd service like this one:
[Unit]
Description=My service
Wants=network-online.target
After=network.target network-online.target
[Service]
Type=oneshot
ExecStart=/my/script.sh
[Install]
WantedBy=default.target
The service is enabled and when I restart the system I have this service ran before the network is up. I know that because in the executed script I'm doing ifconfig > /tmp/ifconfig.txt and I can see that no interface is connected.
Why is the After directive not working properly? Do you have any idea?
Thanks,
Egidio
Offline
What are you using to make network-online.target work?
Offline
I'm using wicd and the service is enable and works properly.
Offline
I cannot easily find anything about wicd supporting network-online.target. Am I missing something or did you misread my question?
If you haven't already, read https://www.freedesktop.org/wiki/Softwa … orkTarget/
Offline
I thought wicd supported network-online.target. If you say it doesn't, then that's obviously the reason why it's not working.
I'm actually working on an AUR package. What if I add the NetworkManager-wait-online.service and systemd-networkd-wait-online.service to the After section but those services don't exist of are disabled? Will the service run anyway? I'm just trying to think about the broadest scenario.
Thank you for your help
Offline
dhcpcd also has a dhcpcd-online program if that floats your boat.
Offline
I'd say, don't mess with any *-online services because their goal is not clear to begin with. If you need to test internet connectivity, just ping some host. For instance, networkmanager (I think) tries to connect to something at fedoraproject.org...
What do you mean by "interface not connected"? No IP address, not authenticated with a wireless AP? If so, your network.target should not be reached. Or wicd just forks dhcp anr/or wpa_supplicant daemon and declares itself done, thus reaching network.target. However, the above daemons can take arbitrary time to do what you call "connect".
Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd
Offline
I'd say, don't mess with any *-online services because their goal is not clear to begin with. If you need to test internet connectivity, just ping some host. For instance, networkmanager (I think) tries to connect to something at fedoraproject.org...
What do you mean by "interface not connected"? No IP address, not authenticated with a wireless AP? If so, your network.target should not be reached. Or wicd just forks dhcp anr/or wpa_supplicant daemon and declares itself done, thus reaching network.target. However, the above daemons can take arbitrary time to do what you call "connect".
Well, for dhcpcd-online, it only says it's online when all of the wait protocols set in dhcpcd.conf have been met.
The default is when any one protocol has fully finished. It makes no claims to working beyond what the protocol defines, ie it will not attempt to contact a fixed host.
The sole reason for it's existence is oddly enough because of systemd.
systemd prefers a non forking model for daemons .... but the normal daemon default (at least for DHCP clients and similar) is to fork once "up".
But because it no longer forks, it needs some other method of saying it's "up".
The other benefit * is that is that it could take down services when the network comes down and restart then when it comes back up.
* This isn't really a benefit, it's just masking tape for a badly written daemon.
Offline
Well, for dhcpcd-online, it only says it's online when all of the wait protocols set in dhcpcd.conf have been met.
This is all well and good, but seems quite tangential to the OPs question.
Unless I really missed something, the OP intends to distribute something that should work on arch systems in general. Relying on the network-online.target being up to indicate network connectivity on arch systems in general is simply not feasible. One can debate until we are blue in the face which package or which developers should be to blame for this, but it doesn't change the facts: network-online.target does not meet the OPs needs.
Pinging an arbitrary domain would work as would checking stats under /sys/class/net
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
This is true.
OK, one thing which may meet the OP's needs is dhcpcd-run-hooks(8) which is still distributed in Arch base system as part of dhcpcd(8) (at least I think so, I don't actually use Arch).
So he can do something like this
$ cat /etc/dhcpcd.exit-hook
#!/bin/sh
if $if_up; then
echo "Interface $interface is considered up" > /tmp/ifstatus
elif $if_down;
echo "Interface $interface is considered down" >/tmp/ifstatus's point
else
echo "Interface $interface is neither up nor down" >/tmp/ifstatus
fi
Of course, this does require using dhcpcd instead of some other tool such as systemd-network, network-manager, connman, dhclient, udhcpc, pump.
EDIT: And that's really the problem isn't it. Any user could be using any of these tools and there is no standard way to query all of them.
This goes back to Trilby's point that -online services are not feasable and my point that they just mask badly written daemons. In your case it looks like you're executing a script. Maybe ping a host in the script to assume connectivity as Tribly suggested.
Last edited by rsmarples (2016-10-17 15:21:36)
Offline
The proper way for a service is to have After=network-online.target
The proper thing for the sysadmin to do is to enable the applicable *-wait-online.service so that it actually delays the network-online.target until it's "online" (for whatever meaning the *-online.service thiks it is online.)
Offline
Leonid.I wrote:I'd say, don't mess with any *-online services because their goal is not clear to begin with. If you need to test internet connectivity, just ping some host. For instance, networkmanager (I think) tries to connect to something at fedoraproject.org...
What do you mean by "interface not connected"? No IP address, not authenticated with a wireless AP? If so, your network.target should not be reached. Or wicd just forks dhcp anr/or wpa_supplicant daemon and declares itself done, thus reaching network.target. However, the above daemons can take arbitrary time to do what you call "connect".
Well, for dhcpcd-online, it only says it's online when all of the wait protocols set in dhcpcd.conf have been met.
The default is when any one protocol has fully finished. It makes no claims to working beyond what the protocol defines, ie it will not attempt to contact a fixed host.The sole reason for it's existence is oddly enough because of systemd.
systemd prefers a non forking model for daemons .... but the normal daemon default (at least for DHCP clients and similar) is to fork once "up".
But because it no longer forks, it needs some other method of saying it's "up".
The other benefit * is that is that it could take down services when the network comes down and restart then when it comes back up.* This isn't really a benefit, it's just masking tape for a badly written daemon.
In archlinux, all *.service files shipped with dhcpcd are Type=forking...
BTW, rsmarples, thx for your work on dhcpcd
Last edited by Leonid.I (2016-10-18 00:48:42)
Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd
Offline