[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Autostart command after network is available (usbip)



On Tue, Feb 08, 2022 at 03:46:09PM +0100, Christian Britz wrote:
> I want to know how I can execute a command as root once after the
> network is available.

> Is this to be done via systemd?

Yes, that's where you should be doing this.

There's one thing in particular that you need to know first, and that's
how Debian defines interfaces for the purposes of determining that
"the network is available".  Assuming that you're using
/etc/network/interfaces (and not Network-Manager or some other thing),
the interfaces that are maked as "auto" must be up, in order for Debian
to declare that the "network is available".

So, make sure your ethernet interface is marked as "auto" and NOT as
"allow-hotplug".

Once that's squared away, the rest is pretty straightforward.

Create a new systemd service (/etc/systemd/system/yourname.service),
and in the [Unit] section, make sure you've got this:

After=network-online.target

That's basically it.  Do the daemon-reload thing, then enable and start
the service, and if it works, reboot to really test it.


Reply to: