[systemd-devel] WiFi device starting a service

Lennart Poettering lennart at poettering.net
Mon Sep 30 18:12:56 PDT 2013


On Sat, 28.09.13 00:22, Paul D. DeRocco (pderocco at ix.netcom.com) wrote:

> I'm working with a Gumstix, and I want to run an "ifup" command when the
> WiFi device becomes available. I'm not sure why, but it always seems to
> become available after the boot process is complete, so I can't use a
> regular service unit tied to something like multi-user.target. So I'm
> trying to have a udev rule launch a service instead. My first guess is
> this:
> 
> /etc/udev/rules.d/wlan0-ifup.rules:
> 
> SUBSYSTEM=="net", KERNEL=="wlan0", \
>     ENV{SYSTEMD_WANTS}+="wlan0-ifup.service"
> 
> /etc/systemd/system/wlan0-ifup.service:
> 
> [Unit]
> Description=Bring wlan0 up
> DefaultDependencies=false
> 
> [Service]
> ExecStart=/sbin/ifup wlan0

Matching to wlan sounds like a poor choice, as on modern systems that's
not how interfaces are named. Also, even on old systems there's no
guarantee that wlan is how things are named.

> 
> Naturally, the service never runs, so it doesn't work. After logging in, I
> can manually start the service, and the WiFi connects, so the problem has
> to be in my udev rule. I ask here, because this seems more
> systemd-specific than udev-specific.
> 
> There's also a rule in 99-systemd.rules:
> 
> SUBSYSTEM=="net", KERNEL!="lo", TAG+="systemd", \
>     ENV{SYSTEMD_ALIAS}+="/sys/subsystem/net/devices/$name"
> 
> I suspect that there's a way to hook something to that, but I can't figure
> out how.
> 
> So what's the right way to do this? Is there a man page specifically for
> this situation?

Something like this should work:

SUBSYSTEM=="net", DEVTYPE=="wlan", ENV{SYSTEMD_WANTS}+="ifup@$name.service"

or so. This will instantiate one instance of ifup at .service per wlan
interface found. (Note however that the DEVTYPE match only works for
clean network drivers which do not implement their own wlan stack, and
which advertise themselves properly).

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list