You are not logged in.
The trick below stopped working with systemd 213.
Hi there,
I was trying to pass DHCP data from systemd-networkd to resolvconf instead of symlinking /run/systemd/network/resolv.conf to /resolv.conf. And this is what I ended up with:
[Service]
ExecStartPost=/bin/sh -c '\
for ((i=5; i; i--)); do\
sleep 1;\
grep -E --quiet --max-count 1 --invert-match "^(#|$)" /run/systemd/network/resolv.conf\
&& /usr/bin/resolvconf -a systemd < /run/systemd/network/resolv.conf\
&& exit 0;\
done;\
exit 1'
ExecStopPost=/usr/bin/resolvconf -d systemd
It works, but maybe someone came up with a better solution. For example,
I used systemd as interface for resolvconf. Is this legal? Should I use anything like eth0, is it possible to obtain it as a %-something?
Is there a sleep with a resolution higher than 1 second? Pauses of 1 second are too long. 100-200ms would be enough, IMO.
Last edited by lorcap (2014-06-11 20:47:47)
Offline
Hi there,
I was trying to pass DHCP data from systemd-networkd to resolvconf instead of symlinking /run/systemd/network/resolv.conf to /resolv.conf. And this is what I ended up with:
[Service] ExecStartPost=/bin/sh -c '\ for ((i=5; i; i--)); do\ sleep 1;\ grep -E --quiet --max-count 1 --invert-match "^(#|$)" /run/systemd/network/resolv.conf\ && /usr/bin/resolvconf -a systemd < /run/systemd/network/resolv.conf\ && exit 0;\ done;\ exit 1' ExecStopPost=/usr/bin/resolvconf -d systemd
It works, but maybe someone came up with a better solution. For example,
I used systemd as interface for resolvconf. Is this legal? Should I use anything like eth0, is it possible to obtain it as a %-something?
Is there a sleep with a resolution higher than 1 second? Pauses of 1 second are too long. 100-200ms would be enough, IMO.
Yes it's legal.
No, POSIX does not support higher resolutions. However, the bash shell does if you want to go that route
But this sounds awfully weird. Why is systemd adding resolv.conf information in the first place?
Offline
No, POSIX does not support higher resolutions. However, the bash shell does if you want to go that route
I search bash manual for "sleep" but I couldn't find anything. Even 'help sleep' returns nothing. How do you do that?
But this sounds awfully weird. Why is systemd adding resolv.conf information in the first place?
I guess you meant why systemd is not adding resolv.conf information.
I think it is by design. At least, if I correctly understand the comment to the patch which added this feature.
Offline
My bad, GNU sleep, not the shell built in.
http://man7.org/linux/man-pages/man1/sleep.1.html
No, I meant what I said. I don't understand what business systemd has writing to resolv.conf.
It's not a DHCP client, nor a network configurator.
Offline
No, I meant what I said. I don't understand what business systemd has writing to resolv.conf.
It's not a DHCP client, nor a network configurator.
systemd doesn't write to any resolve.conf unless a service file is written to make it do so. networkd is a network configurator, and so writes to /run/systemd/network/resolv.conf. If networkd is a system's only network configurator then it is sufficient to symlink /etc/resolve.conf to /run/systemd/network/resolv.conf. If another network configurator is used in conjunction with networkd then /run/systemd/network/resolv.conf must be merged into /etc/resolv.conf. The OP has implemented this merge by calling resolvconf from a systemd service file.
Offline