[systemd-devel] Unit to test if a domain is reachable

Moviuro moviuro at gmail.com
Thu Jul 17 02:37:29 PDT 2014


Hi all!

Since (from my understanding) systemd devel team did not want to interpret nor 
force its interpretation of "network availability" on systemd consumers, we 
have to use some other services and cross fingers (network.target, systemd-
networkd-wait-online.service and so on).

However, everything I tried proved an utter failure: target says reached even 
though it doesn't even have an IP on any link; wait-online obviously didn't 
even check if I had a DNS whatsoever.

In the end, I had to write my own (ugly) service to test if a domain is 
reachable:

/etc/systemd/system/reachable-retry at .service 
[Unit]
Description=Test if %i is reachable
# I'm not even sure it's useful, because it doesn't do its job
After=systemd-networkd-wait-online.service
 
[Service]
Type=forking
ExecStart=/usr/bin/ping -c1 %i
Restart=on-failure
# Needed, else the unit just goes crazy
# if there are no links and systemd stops it
RestartSec=2

# I don't know if the [Install] part is needed
[Install]
WantedBy=multi-user.target

This works but using the Type=forking is an ugly hack: the result I'm waiting 
for would be:
o Call reachable-retry@ in a unit (Requires and After);
o If it fails, try again (seems OK with the Restart directive);
o If it succeeds, the unit that needs to reach %i gets launched and my 
reachable-retry@ *does not* enter SUCCESS or whatever "good" state you can 
think of: it just stays asleep until someone else wants to recheck later if 
the domain is still reachable (e.g. domain goes down, my ISP goes crazy, I 
suspend my computer...).

An other unit I could use would be reachable@ that would simply test whether 
or not a domain is reachable and:
o In case it isn't, prevent a unit from being launched, period.
o In case it is, launch the unit and don't enter any SUCCESS or "good" state.
o If an other unit needs to test afterwards, launch the test again.
Would Type=oneshot do that?

Any input would be greatly appreciated.
The issue was also a bit discussed here:
 https://bbs.archlinux.org/viewtopic.php?id=182717
And here too (in French):
 https://forums.archlinux.fr/topic15485.html

Cheers,
--
Moviuro
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20140717/0bff7b70/attachment.sig>


More information about the systemd-devel mailing list