1

Arch 5.18.12

I have multiple network interfaces and sometimes it takes a few minutes for all of them to connect. However for system startup I need only one -- which one depends on my geographic location.For example sometimes I want to use wifi, sometimes not.

To avoid long startups I modify the /lib/systemd/system/systemd-networkd-wait-online.service by adding --any to the ExecStart line.

 ExecStart=/usr/lib/systemd/systemd-networkd-wait-online --any

This works a charm.

However on updates this file is overwritten so I have a long startup and then I have to modify the service file again.

Is there a more efficient strategy here?

Stephen Boston
  • 2,178
  • 4
  • 32
  • 55
  • Relating https://unix.stackexchange.com/a/458252/117549 – Jeff Schaller Jul 17 '22 at 12:36
  • @JeffSchaller So on Arch I could put my change to /etc/systemd/system/... My concern there is that I'd miss an important update to the service file. It looks as if the usual update to systemd will replace the file with no changes, but how would I know? – Stephen Boston Jul 17 '22 at 13:59
  • 1
    I'm thinking an override might work, but can't test it at the moment. (See https://unix.stackexchange.com/q/398540/117549) – Jeff Schaller Jul 17 '22 at 14:02
  • @JeffSchaller I've put the change to a VM, updated systemd -- which overwrote the /lib/systemd entry and got a reboot without error. It should work but I'm concerned about missin gupdates. – Stephen Boston Jul 17 '22 at 14:04
  • Well, the trouble is that you're editing a system-provided (packaged) file, so you're bound to lose your updates or the package updates. My best idea was to leave the packaged file alone and simply override the one parameter that you want changed. – Jeff Schaller Jul 17 '22 at 14:07

3 Answers3

3

Combining the two ideas from How to override systemd unit file settings?, I would suggest overriding the ExecStart directive by calling systemctl edit systemd-networkd-wait-online.service, which will open an editor; put the stanza below into that file, then save and exit the editor:

[Service]
ExecStart=
ExecStart=/usr/lib/systemd/systemd-networkd-wait-online --any

That command will place a file at /etc/systemd/system/systemd-networkd-wait-online.service.d/override.conf with those contents. The doubled ExecStart directive is not a typo; it's important to first clear the existing contents before setting your own.

Because that /lib/systemd/system/systemd-networkd-wait-online.service file is provided by your package manager, you're bound to lose one update or the other:

  • changes to files under /lib may be lost during package updates
  • changes to the ExecStart directive by the package manager will be overridden by your local override.

It seems to me that the second option is the better choice, since:

  • it's in /etc, which should not be affected by package upgrades (so your change won't be completely lost)
  • you can add comments to the override file explaining what you're doing and why
  • packaged changes to the ExecStart can be merged (or not) into your local override if & when they do happen

If the package decides to rename or otherwise move the systemd-networkd-wait-online program, your override would break until you update it (but if that happened, your change to the file in /lib would also be lost and so your functionality would be lost anyway).

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
0

You can force your manual changes to stay with /lib/systemd/system/systemd-networkd-wait-online.service by running systemctl daemon-reload.

Caveat: it's important to take any changes you made via systemctl edit and add the ones you want to the file in /lib/systemd/system/ before you run the daemon-reload. In particular:

  1. Use cat /etc/systemd/system/systemd-networkd-wait-online.service.d/override.conf to see your changes;
  2. Edit /lib/systemd/system/systemd-networkd-wait-online.service;
  3. Delete /etc/systemd/system/systemd-networkd-wait-online.service.d/override.conf;
  4. systemctl daemon-reload
  5. systemctl restart the systemd-networkd service.
-1

I think you can create a .sh. file that runs a command and associate it with a service. So, and this is just a patch, you should be able to put that ExecStart=/usr/lib/systemd/systemd-networkd-wait-online --any command in a file that will run at startup. I was reading this the other day about creating systemd services. You may be able to change the original file to fit what you need, check the bottom of that page where they create/show an example of creating and installing a service for ethtool. Hope that helps.

  • Thanks for the suggestion but I'm looking for a systemd-level change. I hope that there is some configuration tweak I can make. See comment by JeffSchaller/ Your solution may work but it is a work-around from outside systemd. Not ideal for my requirements. – Stephen Boston Jul 17 '22 at 14:01
  • @InjectedScript you have it backwards, actually. See https://freedesktop.org/software/systemd/man/systemd.unit.html#Unit%20File%20Load%20Path where it describes the files under /etc/ as controlled by the administrator and those under /usr/lib as installed by the package manager. – Jeff Schaller Jul 21 '22 at 12:31
  • Thank you for letting me know! Obviously no one else posted here, but were you able to get an answer? – InjectedScript Jul 21 '22 at 14:06