[systemd-devel] starting/stopping network interfaces with systemd

Cliff Brake cliff.brake at gmail.com
Mon Oct 10 07:42:29 PDT 2011


On Sun, Oct 9, 2011 at 7:52 AM, Mirco Tischler <mt-ml at gmx.de> wrote:
> 2011/10/9 Cliff Brake <cliff.brake at gmail.com>:
>> On Sat, Oct 8, 2011 at 11:09 AM, Cliff Brake <cliff.brake at gmail.com> wrote:
>> However, it does not work for subsequent NIC insertions.  It appears
>> that stop is not getting executed when the device is removed, as
>> network at eth0.service is always listed as active after the NIC is
>> installed, and then removed.
> Hmm, true. I wonder if the ExecStop line is really necessary, as it
> doesn't make sense to execute this after the device is plugged out. So
> if you drop this, you can drop the RemainAfterExit as well and it
> should work for subsequent insertions.

It appears that two things need to happen:

1) we need to run ifdown, as ifup/down keeps track of state in /var/run/ifstate:

root at cm-x270:~# more /var/run/ifstate
eth0=eth0

2) somehow systemd needs to know the interface is stopped before it
will try to start it.  It does not appear that removing the device
currently is triggering any systemd events.  After I remove the NIC:

root at cm-x270:~# systemctl status network at eth0.service
network at eth0.service
         Loaded: loaded (/lib/systemd/system/network at .service; static)
         Active: active (exited) since Mon, 10 Oct 2011 04:48:42 -0500; 47s ago
        Process: 419 ExecStop=/sbin/ifdown %i (code=exited, status=0/SUCCESS)
        Process: 427 ExecStart=/sbin/ifup %i (code=exited, status=0/SUCCESS)
         CGroup: name=systemd:/system/network at .service/eth0
                 └ 446 udhcpc -R -n -p /var/run/udhcpc.eth0.pid -i eth0

root at cm-x270:~# more /var/run/ifstate
eth0=eth0

> Another way that comes to mind might be to add
> ENV{SYSTEMD_ALIAS}="/$name" to the udev rule and add
> "BindTo=%i.device" in the unit section of the service file.

One thing I've been struggling with is finding documentation.  For
instance with BindTo, I start clicking on man pages here
http://0pointer.de/public/systemd-man/.  I guessed systemd.service.hml
first, but after several tries found it at systemd.unit.html.  I would
be very handy to have all the man pages in one HTML or PDF page, as it
seems like this is the best source of systemd documentation that I've
found to date.

It seems BindTo is ideal for this case, so I'll try it next, thanks
for the idea!

BindTo=
Configures requirement dependencies, very similar in style to
Requires=, however in addition to this behaviour it also declares that
this unit is stopped when any of the units listed suddenly disappears.
Units can suddenly, unexpectedly disappear if a service terminates on
its own choice, a device is unplugged or a mount point unmounted
without involvement of systemd.

Cliff

--
=================
http://bec-systems.com


More information about the systemd-devel mailing list