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

Lennart Poettering lennart at poettering.net
Mon Oct 10 11:45:45 PDT 2011


On Fri, 07.10.11 17:24, Cliff Brake (cliff.brake at gmail.com) wrote:

> Hi,
> 
> I'm trying to customize systemd to start/stop network interfaces in an
> embedded system (OpenEmbedded/Angstrom).  Angstrom has some support
> for systemd and its working fairly well so far.  Are there any
> examples I can start with?  Basically, when a network device is
> installed (USB), I'd like to run "ifup eth0", etc.

Debian has a service file for that which pulls in ifup from the udev
device via a template which I believe is quite pretty. Might be worth
looking into that.

We are actually contemplating moving something like a default
ifup at .service file into systemd upstream proper.

> 
> this is what I have so far:
> 
> [Unit]
> Description=Start networking services
> After=syslog.target

Please drop After=syslog.target. It's not necessary anymore.

> 
> [Service]
> ExecStart=/sbin/ifup eth0
> Type=oneshot
> ExecStop=/sbin/ifdown eth0
> StandardOutput=syslog+console

Note that all services default to sylog logging anyway these days, so
i'd recommend removing StandardOutput= here.

> 
> [Install]
> WantedBy=multi-user.target
> 
> but its not working:
> 
> systemctl start network.service
> asix 1-2:1.0: eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
> ifup[756]: udhcpc (v1.18.5) started
> ifup[756]: Sending discover...
> ifup[756]: Sending select for 192.168.1.100...
> ifup[756]: Lease of 192.168.1.100 obtained, lease time 3600
> ifup[756]: adding dns 192.168.1.1
> 
> This all looks good, but then when I do ifconfig, the network devices
> is not configured:
> 
> root at cm-x270:/lib/systemd/system# ifconfig
> lo        Link encap:Local Loopback
>           inet addr:127.0.0.1  Mask:255.0.0.0
>           inet6 addr: ::1/128 Scope:Host
>           UP LOOPBACK RUNNING  MTU:16436  Metric:1
>           RX packets:4 errors:0 dropped:0 overruns:0 frame:0
>           TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
>           collisions:0 txqueuelen:0
>           RX bytes:268 (268.0 B)  TX bytes:268 (268.0 B)
> 
> running ifup eth0 manually works fine.

Hmm, my guess is that $PATH is set differently here and the dhcp
callouts fail with the shorter default $PATH of systemd?

> 
> Beyond this, it would be nice to somehow trigger on when a USB NIC is
> installed and automatically run ifup.  Any pointers would be
> appreciated.

Pull in ifup at .service from the udev rules by setting SYSTEMD_WANTS as
udev property on the them. Check the DEbian patch how to do that.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list